Initial commit
This commit is contained in:
102
api-wiaas/server/components/v1/users/UsersController.php
Normal file
102
api-wiaas/server/components/v1/users/UsersController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
class UsersController{
|
||||
private $model;
|
||||
|
||||
function __construct(){
|
||||
$this->model = new UsersModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* include users template
|
||||
*/
|
||||
public function usersTemplate(){
|
||||
global $user;
|
||||
require_once('templates/UsersTemplate.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* display and edit users
|
||||
* @return array of users
|
||||
*/
|
||||
public function showEditUsersTemplate() {
|
||||
require_once('templates/ShowEditUsersTemplate.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* include create new user template
|
||||
*/
|
||||
public function createUserTemplate(){
|
||||
require_once('templates/CreateUserTemplate.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* include link customers template
|
||||
*/
|
||||
public function linkCustomersTemplate(){
|
||||
require_once('templates/LinkCustomersTemplate.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns json array with all the users from the webshop
|
||||
* @return array with users info
|
||||
*/
|
||||
public function getUsers(){
|
||||
echo json_encode($this->model->getUsers());
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the user types available in the webshop
|
||||
* @return array of user types
|
||||
*/
|
||||
public function getUserTypes() {
|
||||
echo json_encode($this->model->getUserTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the commercial leads from the webshop
|
||||
* @return array with all available commercial leads
|
||||
*/
|
||||
public function getCommercialLeads() {
|
||||
echo json_encode($this->model->getCommercialLeads());
|
||||
}
|
||||
|
||||
/**
|
||||
* add new user in DB
|
||||
* @return confirmation message
|
||||
*/
|
||||
public function saveUserInDB() {
|
||||
$info = isset($_REQUEST['info']) ? $_REQUEST['info'] : '';
|
||||
$commercialLeads = isset($_REQUEST['cl']) ? $_REQUEST['cl'] : '';
|
||||
echo json_encode($this->model->saveUserInDB($info, $commercialLeads));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the list of customers and commercial leads
|
||||
* @return Array list of customers and comemrcial leads
|
||||
*/
|
||||
public function getCustomersAndCl() {
|
||||
echo json_encode($this->model->getCustomersAndCl());
|
||||
}
|
||||
|
||||
public function updateLinkedCustomers(){
|
||||
$idCommercialLead = isset($_REQUEST['idCommercialLead']) ? $_REQUEST['idCommercialLead'] : 0;
|
||||
$customers = isset($_REQUEST['customers']) ? $_REQUEST['customers'] : '[]';
|
||||
echo json_encode($this->model->updateLinkedCustomers($idCommercialLead, $customers));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the list of all the companies available
|
||||
* @return Array all the companies available in the system
|
||||
*/
|
||||
public function getCompanies() {
|
||||
echo json_encode($this->model->getCompanies());
|
||||
}
|
||||
|
||||
/**
|
||||
* open users page
|
||||
*/
|
||||
public function showPage(){
|
||||
global $user;
|
||||
require_once('UsersPage.php');
|
||||
}
|
||||
}
|
||||
630
api-wiaas/server/components/v1/users/UsersModel.php
Normal file
630
api-wiaas/server/components/v1/users/UsersModel.php
Normal file
@@ -0,0 +1,630 @@
|
||||
<?php
|
||||
class UsersModel{
|
||||
/**
|
||||
* @return array with all the users available from the webshop
|
||||
*/
|
||||
public function getUsers() {
|
||||
global $database;
|
||||
|
||||
$sql = "SELECT
|
||||
u.id AS idUser,
|
||||
info.name,
|
||||
info.phone,
|
||||
u.mail,
|
||||
ut.type,
|
||||
u.username,
|
||||
u.isCompanyAdmin
|
||||
FROM
|
||||
(SELECT
|
||||
c.idUser,
|
||||
c.name,
|
||||
c.phone
|
||||
FROM
|
||||
".TABLES['customers']." c
|
||||
UNION
|
||||
SELECT
|
||||
cl.idUser,
|
||||
cl.name,
|
||||
cl.phone
|
||||
FROM
|
||||
".TABLES['commercial_leads']." cl
|
||||
UNION
|
||||
SELECT
|
||||
b.idUser,
|
||||
b.name,
|
||||
b.phone
|
||||
FROM
|
||||
".TABLES['brokers']." b
|
||||
UNION
|
||||
SELECT
|
||||
s.idUser,
|
||||
s.name,
|
||||
s.phone
|
||||
FROM
|
||||
".TABLES['suppliers']." s) info
|
||||
INNER JOIN ".TABLES['rel_user_type']." rut
|
||||
ON rut.idUser = info.idUser
|
||||
INNER JOIN ".TABLES['user_types']." ut
|
||||
ON ut.id = rut.idType
|
||||
INNER JOIN users u
|
||||
ON u.id = info.idUser
|
||||
ORDER BY name";
|
||||
|
||||
$query = $database->query($sql);
|
||||
while($row = $database->fetchArray($query)) {
|
||||
$row['type'] = ucfirst($row['type']);
|
||||
$row['type'] = str_replace('_', ' ', $row['type']);
|
||||
$data[$row['type']][] = $row;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all the user tyeps/roles from the DB
|
||||
* @return Array of user types
|
||||
*/
|
||||
public function getUserTypes() {
|
||||
global $database;
|
||||
$data=[];
|
||||
|
||||
$sql = "SELECT
|
||||
id,
|
||||
type AS name
|
||||
FROM ".TABLES['user_types']."
|
||||
";
|
||||
|
||||
$query = $database->query($sql);
|
||||
while($row = $database->fetchArray($query)){
|
||||
$row['name'] = ucfirst($row['name']);
|
||||
$row['name'] = str_replace('_', ' ', $row['name']);
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all the commercial leads from the DB
|
||||
* @return Array with all the commercial leads
|
||||
*/
|
||||
public function getCommercialLeads() {
|
||||
global $database;
|
||||
|
||||
$sql = "SELECT
|
||||
id,
|
||||
name
|
||||
FROM ".TABLES['commercial_leads']."
|
||||
";
|
||||
|
||||
return $database->fetchResultArray($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param info - array with all the details regarding new user
|
||||
* @param commercialLeads - array with all the commercial leads
|
||||
* @return Array array with the code and the message of confirmation for adding the user in the DB
|
||||
*/
|
||||
public function saveUserInDB($info, $commercialLeads = '') {
|
||||
global $database;
|
||||
$info = (array) json_decode($info);
|
||||
$commercialLeads = json_decode($commercialLeads);
|
||||
$data = [];
|
||||
|
||||
foreach($info as $key => $value) {
|
||||
$info['$key'] = $database->escapeValue($value);
|
||||
$checkMessage = $database->isEmpty($key, $value);
|
||||
if($checkMessage){
|
||||
$data['messages'][] = $checkMessage;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
$messageData = $this->validateUserData($info, $commercialLeads);
|
||||
if(!empty($messageData)){
|
||||
return $messageData;
|
||||
}
|
||||
|
||||
$token = bin2hex(random_bytes(16));
|
||||
$idUser = $this->getInsertedIdForUsers($info, $token);
|
||||
if(is_array($idUser)) {
|
||||
return $idUser;
|
||||
}
|
||||
|
||||
if($data = $this->insertUserTypeRelation($idUser, $info['idUserType'])) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = $this->insertUserInfo($idUser, $info, $commercialLeads);
|
||||
$info['type'] = $this->getUserTypeByIdForMail($info['idUserType']);
|
||||
$data['messages'][] = UtilsModel::sendUserConfirmationMail($info, $info['mail'], 'create', $token);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* get user type by id for mail
|
||||
* @param Int $idUserType the id of the user type
|
||||
* @return String 'customer' or 'other' based on the user type
|
||||
*/
|
||||
private function getUserTypeByIdForMail($idUserType) {
|
||||
global $database;
|
||||
|
||||
$sql = "SELECT type FROM ".TABLES['user_types']." ut WHERE ut.id=".$idUserType;
|
||||
$result = $database->fetchResultArray($sql);
|
||||
|
||||
return $result && $result[0]['type'] === USER_TYPES['CUSTOMER'] ? 'customer' : 'other';
|
||||
}
|
||||
|
||||
/**
|
||||
* validate user data from GUI
|
||||
* @param Array $info all information about the user to be inserted
|
||||
* @param Array $commercialLeads all the commercial leads linked to a customer
|
||||
* @return Array empty or error message
|
||||
*/
|
||||
private function validateUserData($info, $commercialLeads) {
|
||||
global $database;
|
||||
$data = [];
|
||||
|
||||
if(!$info['idUserType']) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'SELECT_USER_TYPE'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
if($info['idUserType'] === '2' && empty($commercialLeads)) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'NO_COMMERCIAL_LEAD_LINK'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
if(!isset($info['name']) || empty($info['name'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ADD_NAME'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
$checkMessage = $database->invalidLength('name', $info['name'], 70);
|
||||
if($checkMessage){
|
||||
$data['messages'][] = $checkMessage;
|
||||
}
|
||||
|
||||
if(array_key_exists('selectedCompanyId', $info)) {
|
||||
if(!$info['selectedCompanyId']) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'COMPANY_EMPTY'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if(!array_key_exists('selectedCompanyId', $info)) {
|
||||
if(!isset($info['companyName']) || empty($info['companyName'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ADD_COMPANY_NAME'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
$checkMessage = $database->invalidLength('companyName', $info['companyName'], 100);
|
||||
if($checkMessage){
|
||||
$data['messages'][] = $checkMessage;
|
||||
}
|
||||
|
||||
if(!isset($info['vat']) || empty($info['vat'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ADD_VAT'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($info['phone']) || empty($info['phone'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ADD_PHONE'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
if(!preg_match('/^([0-9\(\)\/\+ \-]*)$/', $info['phone'])){
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'INVALID_PHONE_NUMBER'
|
||||
];
|
||||
}
|
||||
|
||||
$checkMessage = $database->invalidLength('phone', $info['phone'], 40);
|
||||
if($checkMessage){
|
||||
$data['messages'][] = $checkMessage;
|
||||
}
|
||||
|
||||
if(!isset($info['username']) || empty($info['username'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ADD_USERNAME'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
$checkMessage = $database->invalidLength('username', $info['username'], 20);
|
||||
if($checkMessage){
|
||||
$data['messages'][] = $checkMessage;
|
||||
}
|
||||
|
||||
if(!preg_match('/^[a-zA-Z\d\.\-_]+$/',$info['username'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'INVALID_USERNAME'
|
||||
];
|
||||
}
|
||||
|
||||
$sql = "SELECT username
|
||||
FROM ".TABLES['users']."
|
||||
WHERE username='".$info['username']."'
|
||||
LIMIT 1";
|
||||
$result = $database->query($sql);
|
||||
if($database->numRows($result) > 0) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'USERNAME_EXISTS'
|
||||
];
|
||||
}
|
||||
|
||||
if(!isset($info['mail']) || empty($info['mail'])) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ADD_MAIL'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
if(!filter_var($info['mail'], FILTER_VALIDATE_EMAIL)){
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'INVALID_MAIL'
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts username, password and mail into users table
|
||||
* @param String $info the data array with all user info
|
||||
* @param String $token the token for newly created user
|
||||
* @return Int the id of the user inserted
|
||||
*/
|
||||
private function getInsertedIdForUsers($info, $token) {
|
||||
global $database, $user;
|
||||
$tokenTimestamp = new DateTime();
|
||||
|
||||
if(!array_key_exists('selectedCompanyId', $info)) {
|
||||
$idCompany = $this->insertCompanyAndReturnId($info['companyName'], $info['vat']);
|
||||
|
||||
if(is_array($idCompany)) {
|
||||
return $idCompany;
|
||||
}
|
||||
} else {
|
||||
$idCompany = $info['selectedCompanyId'];
|
||||
}
|
||||
$isCompanyAdmin = array_key_exists('companyAdmin', $info) && $info['companyAdmin'] ? 1 : 0;
|
||||
|
||||
$sql = "INSERT INTO ".TABLES['users']." (idCompany, username, mail, token, tokenTS, isCompanyAdmin)
|
||||
VALUES (
|
||||
$idCompany,
|
||||
'".$info['username']."',
|
||||
'".$info['mail']."',
|
||||
'".$token."',
|
||||
'".$tokenTimestamp->format('Y-m-d H:i:s')."',
|
||||
$isCompanyAdmin
|
||||
)";
|
||||
$result = $database->query($sql);
|
||||
|
||||
return $database->getInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts the new company data
|
||||
* @param String $name the name of the company
|
||||
* @param String $vat the vat code for the company
|
||||
* @return Int the id of the company inserted
|
||||
*/
|
||||
private function insertCompanyAndReturnId($name, $vat) {
|
||||
global $database;
|
||||
|
||||
$sql = "SELECT name FROM ".TABLES['company']." WHERE name='$name'";
|
||||
$query = $database->query($sql);
|
||||
if($database->numRows($query)) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'warning',
|
||||
'message' => 'COMPANY_EXISTS'
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ".TABLES['company']."
|
||||
(vatCode, name)
|
||||
VALUES
|
||||
('$vat', '$name')
|
||||
";
|
||||
$result = $database->query($sql);
|
||||
|
||||
return $database->getInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts the relation between user and user type
|
||||
* @param Int $idUser id of the user inserted
|
||||
* @param Int $idType id of the user type to be inserted
|
||||
* @return Array empty or error message
|
||||
*/
|
||||
private function insertUserTypeRelation($idUser, $idType) {
|
||||
global $database;
|
||||
$data = [];
|
||||
|
||||
$sql = "INSERT INTO ".TABLES['rel_user_type']."
|
||||
VALUES(
|
||||
$idUser,
|
||||
$idType
|
||||
)";
|
||||
$result = $database->query($sql);
|
||||
|
||||
if(!$database->affectedRows()) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ERROR_USER_TYPE'
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* insert user information
|
||||
* @param Int $idUser id of the user inserted
|
||||
* @param Array $info all the information needed for the user
|
||||
* @param Array $commercialLeads commercial leads to link to customer
|
||||
* @return Array confirmation message
|
||||
*/
|
||||
private function insertUserInfo($idUser, $info, $commercialLeads) {
|
||||
global $database;
|
||||
$data = [];
|
||||
$shouldLinkCommercialLeads = false;
|
||||
|
||||
switch ($info['idUserType']) {
|
||||
// broker
|
||||
case '1':
|
||||
$table = TABLES['brokers'];
|
||||
break;
|
||||
// customer
|
||||
case '2':
|
||||
$table = TABLES['customers'];
|
||||
$shouldLinkCommercialLeads = true;
|
||||
break;
|
||||
// commercial lead
|
||||
case '3':
|
||||
$table = TABLES['commercial_leads'];
|
||||
break;
|
||||
// supplier
|
||||
case '4':
|
||||
$table = TABLES['suppliers'];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO $table (idUser, name, phone)
|
||||
VALUES (
|
||||
".$idUser.",
|
||||
'".$info['name']."',
|
||||
'".$info['phone']."'
|
||||
)";
|
||||
$result = $database->query($sql);
|
||||
if($database->affectedRows()) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'success',
|
||||
'message' => 'USER_INSERTED'
|
||||
];
|
||||
} else {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ERROR_USER_INFO'
|
||||
];
|
||||
}
|
||||
|
||||
if($shouldLinkCommercialLeads) {
|
||||
$idCustomer = $database->getInsertId();
|
||||
$values = '';
|
||||
foreach($commercialLeads as $commercialLead) {
|
||||
$values .= "(".$commercialLead->id.", $idCustomer),";
|
||||
}
|
||||
$values = rtrim($values, ',');
|
||||
|
||||
$sql = "INSERT INTO ".TABLES['rel_commercial_lead_customers']."
|
||||
(idCommercialLead, idCustomer)
|
||||
VALUES $values";
|
||||
$result = $database->query($sql);
|
||||
|
||||
if(!$database->affectedRows()) {
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'ERROR_USER_CL'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* get customers linked to comemrcial leads
|
||||
* @return Array list of customers grouped by commercial lead id
|
||||
*/
|
||||
private function getCommercialLeadsCustomers(){
|
||||
global $database;
|
||||
$data = [];
|
||||
|
||||
$sql = "SELECT
|
||||
rclc.idCommercialLead,
|
||||
rclc.idCustomer as id,
|
||||
c.name
|
||||
FROM ".TABLES['rel_commercial_lead_customers']." rclc
|
||||
INNER JOIN ".TABLES['customers']." c
|
||||
ON c.id=rclc.idCustomer
|
||||
WHERE rclc.isLinkEnabled=1
|
||||
ORDER BY name";
|
||||
$query = $database->query($sql);
|
||||
while($row = $database->fetchArray($query)){
|
||||
$data[$row['idCommercialLead']][] = $row;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all customers and commercial leads in the system (included linked custoemrs to commercial lead)
|
||||
* @return Array list of customers and list of commercial leads
|
||||
*/
|
||||
public function getCustomersAndCl() {
|
||||
global $database;
|
||||
$data = [];
|
||||
$clCustomers = $this->getCommercialLeadsCustomers();
|
||||
|
||||
$sql = "SELECT
|
||||
c.id AS id,
|
||||
c.name AS name,
|
||||
'customers' AS userType
|
||||
FROM ".TABLES['customers']." c
|
||||
UNION ALL
|
||||
SELECT
|
||||
cl.id AS id,
|
||||
cl.name AS name,
|
||||
'commercialLeads' AS userType
|
||||
FROM ".TABLES['commercial_leads']." cl
|
||||
ORDER BY userType, name";
|
||||
$query = $database->query($sql);
|
||||
while($row = $database->fetchArray($query)){
|
||||
if($row['userType'] === 'commercialLeads'){
|
||||
$row['linkedCustomers'] = isset($clCustomers[$row['id']]) ? $clCustomers[$row['id']] : [];
|
||||
}
|
||||
$data[$row['userType']][] = $row;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* update customers for a commercial lead
|
||||
* @param INT $idCommercialLead id for the commercial lead
|
||||
* @param Array $customers list of customers to be linked
|
||||
* @return Array update message
|
||||
*/
|
||||
public function updateLinkedCustomers($idCommercialLead, $customers){
|
||||
global $database;
|
||||
$data = [];
|
||||
$idCommercialLead = $database->escapeValue($idCommercialLead);
|
||||
$customers = json_decode($customers);
|
||||
|
||||
if(intval($idCommercialLead) == 0){
|
||||
$data['messages'][] = [
|
||||
'code' => 'error',
|
||||
'message' => 'INVALID_COMMERCIAL_LEAD'
|
||||
];
|
||||
}
|
||||
|
||||
$sqlCustomers = "SELECT rclc.idCustomer
|
||||
FROM ".TABLES['rel_commercial_lead_customers']." rclc
|
||||
WHERE idCommercialLead=$idCommercialLead";
|
||||
$query = $database->query($sqlCustomers);
|
||||
$availableCustomers = [];
|
||||
while($row = $database->fetchArray($query)){
|
||||
$availableCustomers[] = $row['idCustomer'];
|
||||
}
|
||||
|
||||
$sqlIns = "";
|
||||
$customersToUpdate = [];
|
||||
$updated = 0;
|
||||
foreach ($customers as $customer) {
|
||||
if(!in_array($customer->id, $availableCustomers)){
|
||||
$customer->id = $database->escapeValue($customer->id);
|
||||
$sqlIns .= "($idCommercialLead, ".$customer->id."),";
|
||||
}
|
||||
|
||||
$customersToUpdate[] = $customer->id;
|
||||
}
|
||||
$sqlIns = rtrim($sqlIns, ',');
|
||||
|
||||
if(!empty($sqlIns)){
|
||||
$sql = "INSERT IGNORE INTO ".TABLES['rel_commercial_lead_customers']."
|
||||
(idCommercialLead, idCustomer)
|
||||
VALUES $sqlIns";
|
||||
$query = $database->query($sql);
|
||||
$updated += $database->affectedRows();
|
||||
}
|
||||
|
||||
if(!empty($customersToUpdate)){
|
||||
$customersToUpdate = implode(',', $customersToUpdate);
|
||||
$sqlUpd = "UPDATE ".TABLES['rel_commercial_lead_customers']."
|
||||
SET isLinkEnabled=1
|
||||
WHERE idCommercialLead=$idCommercialLead AND idCustomer IN($customersToUpdate)";
|
||||
$query = $database->query($sqlUpd);
|
||||
$updated += $database->affectedRows();
|
||||
|
||||
$sqlUnlink = "UPDATE ".TABLES['rel_commercial_lead_customers']."
|
||||
SET isLinkEnabled=0
|
||||
WHERE idCommercialLead=$idCommercialLead AND idCustomer NOT IN($customersToUpdate)";
|
||||
$query = $database->query($sqlUnlink);
|
||||
$updated += $database->affectedRows();
|
||||
}
|
||||
|
||||
|
||||
if($updated > 0){
|
||||
$data['messages'][] = [
|
||||
'code' => 'success',
|
||||
'message' => 'CUSTOMERS_LINKED_TO_CL'
|
||||
];
|
||||
}else{
|
||||
$data['messages'][] = [
|
||||
'code' => 'warning',
|
||||
'message' => 'NO_CHANGES'
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the companies name and id
|
||||
* @return Array companies available in the application
|
||||
*/
|
||||
public function getCompanies() {
|
||||
global $database;
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
c.id,
|
||||
c.name
|
||||
FROM
|
||||
".TABLES['company']." c
|
||||
ORDER BY name";
|
||||
|
||||
return $database->fetchResultArray($sql);
|
||||
}
|
||||
}
|
||||
9
api-wiaas/server/components/v1/users/UsersPage.php
Normal file
9
api-wiaas/server/components/v1/users/UsersPage.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<script src="<?php echo PATH_JS_COMPONENTS.'users/users.directive.js?v='.APPLICATION_VERSION;?>" type="text/javascript"></script>
|
||||
<script src="<?php echo PATH_JS_COMPONENTS.'users/show-edit-users.directive.js?v='.APPLICATION_VERSION;?>" type="text/javascript"></script>
|
||||
<script src="<?php echo PATH_JS_COMPONENTS.'users/create-user.directive.js?v='.APPLICATION_VERSION;?>" type="text/javascript"></script>
|
||||
<script src="<?php echo PATH_JS_COMPONENTS.'users/link-customers.directive.js?v='.APPLICATION_VERSION;?>" type="text/javascript"></script>
|
||||
|
||||
<div id="users" class="container-fluid col-md-12">
|
||||
<h1>{{ 'users.TITLE' | translate }}</h1>
|
||||
<users ng-controller="usersCtrl"></users>
|
||||
</div>
|
||||
@@ -0,0 +1,5 @@
|
||||
<button type="button"
|
||||
id="create-user-button"
|
||||
subModule="createUser"
|
||||
class="btn btn-default"
|
||||
ng-click="setSubModule($event)">{{ 'users.buttons.CREATE_USER' | translate }}</button>
|
||||
@@ -0,0 +1,4 @@
|
||||
<div id="create-user-layer"
|
||||
ng-if="isSubmoduleVisible('createUser')">
|
||||
<create-user ng-controller="createUserCtrl" ng-init="getDataForUserCreation()"></create-user>
|
||||
</div>
|
||||
@@ -0,0 +1,149 @@
|
||||
<div id="create-user-template-container" class="col-md-12">
|
||||
<h3>{{ 'users.headers.CREATE_USER' | translate }}</h3>
|
||||
|
||||
<form>
|
||||
<div id="user-whole-container" class="col-md-12">
|
||||
<div id="create-user-page-one">
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-2">{{ 'users.labels.NAME' | translate }}</label>
|
||||
<input type="text" required class="col-md-4" id="user-name" ng-model="info.name"
|
||||
placeholder="{{ 'users.placeholders.NAME' | translate }}" />
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-2">{{ 'users.labels.COMPANY' | translate }}</label>
|
||||
<select id="company-name"
|
||||
class="form-control-static col-md-2 {{getClassForCompany()}}"
|
||||
ng-disabled="showAddNewCompany"
|
||||
ng-model="companySelected"
|
||||
ng-change="selectCompany()"
|
||||
ng-options="company.name for company in availableCompanies track by company.id">
|
||||
</select>
|
||||
<div id="add-new-company-button" class="col-md-1">
|
||||
<input type="button"
|
||||
id="add-new-company"
|
||||
class="btn btn-info"
|
||||
ng-click="toggleNewCompany()"
|
||||
value="{{ 'users.buttons.ADD_NEW_COMPANY' | translate }}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="new-company-details-container col-md-12" ng-if="showAddNewCompany">
|
||||
<div class="label-value-pair col-md-12 new-company-details">
|
||||
<label class="col-md-2">{{ 'users.labels.COMPANY_NAME' | translate }}</label>
|
||||
<input type="text" class="col-md-4" id="new-company-name" ng-model="info.companyName"
|
||||
placeholder="{{ 'users.placeholders.COMPANY_NAME' | translate }}" />
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12 new-company-details">
|
||||
<label class="col-md-2">{{ 'users.labels.VAT' | translate }}</label>
|
||||
<input type="text" class="col-md-4" id="new-company-vat-number" ng-model="info.vat"
|
||||
placeholder="{{ 'users.placeholders.VAT' | translate }}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12 company-admin-box">
|
||||
<input type="checkbox" id="user-as-company-admin" name="companyAdmin" ng-model="info.companyAdmin">
|
||||
<label for="companyAdmin">{{'users.labels.COMPANY_ADMIN' | translate}}</label>
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-2">{{ 'users.labels.PHONE' | translate }}</label>
|
||||
<input type="text" class="col-md-2" id="user-phone" ng-model="info.phone"
|
||||
placeholder="{{ 'users.placeholders.PHONE' | translate }}" required />
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-2">{{ 'users.labels.MAIL' | translate }}</label>
|
||||
<input type="email" class="col-md-4" id="user-mail" ng-model="info.mail"
|
||||
placeholder="{{ 'users.placeholders.MAIL' | translate }}" required />
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-2">{{ 'users.labels.USER_TYPE' | translate }}</label>
|
||||
<select id="user-type"
|
||||
class="form-control-static col-md-2"
|
||||
ng-model="userTypeSelected"
|
||||
ng-change="checkIfCLIsNeeded()"
|
||||
ng-options="role.name for role in roles track by role.id"
|
||||
required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-2">{{ 'users.labels.USERNAME' | translate }}</label>
|
||||
<input type="text" class="col-md-4" id="username" ng-model="info.username"
|
||||
placeholder="{{ 'users.placeholders.USERNAME' | translate }}" required />
|
||||
</div>
|
||||
<div class="label-value-pair col-md-12">
|
||||
<label class="col-md-8">{{ 'users.forms.messages.AUTOMATIC_PASSWORD' | translate }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="create-user-page-two" ng-if="isSelectCLVisible()" class="col-md-12">
|
||||
<div class="alert alert-info">
|
||||
<span class="glyphicon glyphicon-info-sign"></span>
|
||||
{{'users.headers.SET_COMMERCIAL_LEAD' | translate}}
|
||||
</div>
|
||||
<div id="choose-commercial-leads-container">
|
||||
<div class="col-md-12">
|
||||
<div class="choose-cl-title col-md-4">
|
||||
{{'users.headers.SELECT_CL' | translate}}
|
||||
</div>
|
||||
<div class="choose-cl-title col-md-5">
|
||||
{{'users.headers.SELECTED_CL' | translate}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="choose-cl-lists-container" class="cl-lists col-md-12">
|
||||
<div class="choose-cl col-md-4">
|
||||
<div id="available-cl-list-container"
|
||||
class="choose-cl-list"
|
||||
data-drop="true"
|
||||
jqyoui-droppable="{onDrop:'droppedCommercialLead(\'available\')'}">
|
||||
<div ng-repeat="(key, clInfo) in availableCommercialLeads"
|
||||
data-drag="true"
|
||||
jqyoui-draggable="{animate:true, onStart:'startEventStyle(\'available\', key)', onStop:'endEventStyle()', scroll: false}"
|
||||
data-jqyoui-options="{revert: 'invalid', containment:'#choose-cl-lists-container', scroll: false}">
|
||||
<div class="link-cl-user choose-cl-row">
|
||||
<label class="link-cl-user-header">
|
||||
{{'users.forms.labels.NAME' | translate}}:
|
||||
</label>
|
||||
<div class="link-cl-user-data">
|
||||
{{clInfo.name}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="draggable-icon col-md-1">
|
||||
<span class="glyphicon glyphicon-transfer"></span>
|
||||
</div>
|
||||
|
||||
<div class="choose-cl col-md-4">
|
||||
<div id="selected-cl-list-container"
|
||||
class="choose-cl-list"
|
||||
data-drop="true"
|
||||
jqyoui-droppable="{onDrop:'droppedCommercialLead(\'selected\')'}">
|
||||
<div ng-repeat="(key, clInfo) in selectedCommercialLeads"
|
||||
data-drag="true"
|
||||
jqyoui-draggable="{animate:true, onStart:'startEventStyle(\'selected\', key)', onStop:'endEventStyle()', scroll: false}"
|
||||
data-jqyoui-options="{revert: 'invalid', containment:'#choose-cl-lists-container', scroll: false}">
|
||||
<div class="link-cl-user choose-cl-row">
|
||||
<label class="link-cl-user-header">
|
||||
{{'users.forms.labels.NAME' | translate}}:
|
||||
</label>
|
||||
<div class="link-cl-user-data">
|
||||
{{clInfo.name}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="user-action-buttons" class="col-md-12">
|
||||
<input type="submit"
|
||||
id="add-new-user"
|
||||
class="btn btn-info"
|
||||
ng-click="saveUserInDB()"
|
||||
value="{{ 'users.buttons.SAVE' | translate }}"/>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,5 @@
|
||||
<button type="button"
|
||||
id="link-customer-button"
|
||||
subModule="linkCustomers"
|
||||
class="btn btn-default"
|
||||
ng-click="setSubModule($event)">{{ 'users.buttons.LINK_CUSTOMERS' | translate }}</button>
|
||||
@@ -0,0 +1,4 @@
|
||||
<div id="link-customers-layer"
|
||||
ng-if="isSubmoduleVisible('linkCustomers')">
|
||||
<link-customers ng-controller="linkCustomersCtrl" ng-init="getCustomersAndCl()"></link-customers>
|
||||
</div>
|
||||
@@ -0,0 +1,65 @@
|
||||
<div id="link-customers-template-container" class="col-md-12">
|
||||
<h3>{{ 'users.headers.LINK_CUSTOMERS' | translate }}</h3>
|
||||
|
||||
<div class="all-commercial-leads-layer col-md-4">
|
||||
<div class="user-container">
|
||||
<div class="user-header">{{ 'users.headers.SELECT_COMMERCIAL_LEAD' | translate }}</div>
|
||||
<div class="user-list">
|
||||
<div ng-click="selectCommercialLead(commercialLead)" class="user-layer {{getUserClass(commercialLead)}}" ng-repeat="commercialLead in commercialLeads">
|
||||
{{commercialLead.name}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="user-link-area col-md-8">
|
||||
<div class="user-big-container col-md-12">
|
||||
<div class="col-md-6">
|
||||
<div id="linked-customers"
|
||||
class="user-container"
|
||||
data-drop="true"
|
||||
jqyoui-droppable="{onDrop:'customerDropped(\'linked-customers\')'}">
|
||||
<div class="user-header">{{ 'users.headers.LINKED_CUSTOMERS' | translate }}</div>
|
||||
<div id="linked-customers-list" class="user-list">
|
||||
<div class="linked-customers-layer customer-row"
|
||||
ng-repeat="customer in selectedCommercialLead.linkedCustomers"
|
||||
data-drag="true"
|
||||
id-customer="{{customer.id}}"
|
||||
drop-to="all-customers"
|
||||
jqyoui-draggable="{animate:true, onStart:'customerDragStart(\'linked-customers-list\')', onStop:'customerDragStop(\'linked-customers-list\')', scroll: false}"
|
||||
data-jqyoui-options="{revert: true}">
|
||||
{{customer.name}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div id="all-customers"
|
||||
class="user-container"
|
||||
data-drop="true"
|
||||
jqyoui-droppable="{onDrop:'customerDropped(\'all-customers\')'}">
|
||||
<div class="user-header">{{ 'users.headers.ALL_CUSTOMERS' | translate }}</div>
|
||||
<div id="all-customers-list" class="user-list">
|
||||
<div ng-if="customer.isNotLinked"
|
||||
class="all-custoemrs-layer customer-row"
|
||||
ng-repeat="customer in customers"
|
||||
data-drag="true"
|
||||
id-customer="{{customer.id}}"
|
||||
drop-to="linked-customers"
|
||||
jqyoui-draggable="{animate:true, onStart:'customerDragStart(\'all-customers-list\')', onStop:'customerDragStop(\'all-customers-list\')', scroll: false}"
|
||||
data-jqyoui-options="{revert: true}">
|
||||
{{customer.name}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="users-link-buttons col-md-12">
|
||||
<div class="btn btn-primary" ng-click="updateLinkedCustomers()">
|
||||
{{ 'users.buttons.SAVE' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,73 @@
|
||||
<div id="show-users">
|
||||
<div class="search-input">
|
||||
<div class="search-icon glyphicon glyphicon-search"></div>
|
||||
<input placeholder="{{'users.placeholders.SEARCH' | translate}}" ng-model="searchText" class="col-md-2">
|
||||
</div>
|
||||
<div class="col-md-12 user-types-container" ng-repeat="(type, userTypes) in users track by type">
|
||||
<div class="col-md-12 user-type-show alert-info">
|
||||
{{type}}
|
||||
</div>
|
||||
<div class="col-md-3" ng-repeat="userInfo in userTypes | filter:searchText">
|
||||
<div class="show-users-layer">
|
||||
<h5 class="company-name-info-title">
|
||||
<div class="info-icon glyphicon glyphicon-briefcase"></div>
|
||||
<div class="show-users-title">
|
||||
{{userInfo.name}}
|
||||
<span ng-if="userInfo.isCompanyAdmin == 1">
|
||||
(<div class="info-icon glyphicon glyphicon-wrench"></div>)
|
||||
</span>
|
||||
</div>
|
||||
</h5>
|
||||
<div class="users-informations-container">
|
||||
<div class="users-data">
|
||||
<div class="users-info">
|
||||
<div class="info-icon glyphicon glyphicon-earphone"></div>
|
||||
<div class="show-users-title">{{userInfo.phone}}</div>
|
||||
</div>
|
||||
<div class="users-info">
|
||||
<div class="info-icon glyphicon glyphicon-envelope"></div>
|
||||
<div class="show-users-title">{{userInfo.mail}}</div>
|
||||
</div>
|
||||
<div class="users-info">
|
||||
<div class="info-icon glyphicon glyphicon-tag"></div>
|
||||
<div class="show-users-title">{{type}}</div>
|
||||
</div>
|
||||
<div class="users-info">
|
||||
<div class="info-icon glyphicon glyphicon-user"></div>
|
||||
<div class="show-users-title">{{userInfo.username}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="users-info-button">
|
||||
<a href="profileSettings?subModule=editProfile&idUser={{userInfo.idUser}}">
|
||||
<div id="edit-user-btn" class="btn btn-primary">
|
||||
{{'users.buttons.EDIT_USER' | translate}}
|
||||
</div>
|
||||
</a>
|
||||
<div id="forget-password-btn" class="btn btn-primary" ng-click="showHideDialog(userInfo)">
|
||||
{{'users.buttons.FORGET_PASSWORD' | translate}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div><h4>Legend:</h4></div>
|
||||
<div>
|
||||
<div class="info-icon glyphicon glyphicon-wrench"></div> is company admin
|
||||
</div>
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="generate-password-dialog-confirm"
|
||||
dialog
|
||||
ng-if="isDialogVisible"
|
||||
on-confirmation="generateTokenForUserPassword"
|
||||
on-close="showHideDialog"
|
||||
is-modal="true"
|
||||
has-buttons="true"
|
||||
parameters="userSelected"
|
||||
title="{{'users.headers.GENERATE_PASSWORD' | translate}}">
|
||||
<p><span class="glyphicon glyphicon-warning-sign"></span>{{'users.forms.messages.GENERATE_PASSWORD' | translate}}?</p>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<button type="button"
|
||||
id="usersBtn"
|
||||
subModule="users"
|
||||
class="btn btn-default"
|
||||
ng-click="setSubModule($event)">{{ 'users.buttons.SHOW_USERS' | translate }}</button>
|
||||
|
||||
|
||||
<?php
|
||||
if($user->getUserType() === USER_TYPES['BROKER']){
|
||||
require_once('CreateUserButton.html');
|
||||
require_once('LinkCustomersButton.html');
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12"
|
||||
id="users-layer"
|
||||
ng-if="isSubmoduleVisible('users')">
|
||||
<h3>{{ 'users.headers.SHOW_USERS' | translate }}</h3>
|
||||
<show-edit-users ng-controller="showEditUsersCtrl" ng-init="getUsers()"></show-edit-users>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if($user->getUserType() === USER_TYPES['BROKER']){
|
||||
require_once('CreateUserLayer.html');
|
||||
require_once('LinkCustomersLayer.html');
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user