| Current Path : /var/www/html/mmishra/erp/controllers/ |
| Current File : /var/www/html/mmishra/erp/controllers/erpa_controller.php |
<?php
//if (!class_exists($erpController)) {
require_once __DIR__."/erp_controller.php";
//}
class erpaController extends erpController {
var $model;
public function __construct($model) {
// call parent constructor
// parent::__construct();
// initialize variables
$this->model = $model;
$this->model->tupleID = $this->tuple;
$this->userIP = $this->getIP(); // requires in log entry
$this->appURL = $_SERVER["REQUEST_URI"]; // this is Request URI for log entry
$this->referer = $_SERVER["HTTP_REFERER"]; // requires for log entry, not mandatory
// maintain erp activity log for inner contents
if ($_SESSION["loginID"] && strpos($this->appURL, 'inner')) {
$this->model->erpLog($this->userIP, $this->appURL, $this->referer);
} else if ($this->model->getMenuProtection($this->menu)) {
print("<h1>Session expired. Please sign-in again.</h1>");
exit;
} }
public function __destruct() {
// echo $erpModel->sqlCommand;//'Destroying: ', $this->moduleID, PHP_EOL;
// log sql operation on corresponding table
// call $erpModel->erpSql($sql);
// print("Thanks.");
}
public function manageConfiguration($action, $configID) {
$this->model->tableID = 'erp_configurations';
$this->model->tupleID = $configID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
// save record
$ownerName = $_POST['ownerName'];
$ownerAddress = $_POST['ownerAddress'];
$ownerPhone = $_POST['ownerPhone'];
$ownerEmail = $_POST['ownerEmail'];
$ownerWWW = $_POST['ownerWWW'];
$supportTeam = $_POST['supportTeam'];
$supportPhone = $_POST['supportPhone'];
$supportEmail = $_POST['supportEmail'];
$copyrightInfo = $_POST['copyrightInfo'];
$erpBaseURL = $_POST['erpBaseURL'];
$autoMailing = $_POST['autoMailing'];
$remark = $_POST['remark'];
if (strpos('http', $ownerWWW)) $ownerWWW = "http://$ownerWWW";
if (strpos('http', $erpBaseURL)) $erpBaseURL = "http://$erpBaseURL";
$this->model->saveConfiguration($ownerName,$ownerAddress,$ownerPhone,$ownerEmail,$ownerWWW,$supportTeam,$supportPhone,$supportEmail,$copyrightInfo,$erpBaseURL,$autoMailing,$remark);
$this->model->sqlLog();
$this->errorText = 'ERP configuration saved successfully.';
break;
}
return $this->model->tupleID;
}
public function manageInstitute($action, $instituteID) {
$this->model->tableID = 'erp_institutes';
$this->model->tupleID = $instituteID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
// save record
$instituteCode = $_POST['instituteCode'];
$instituteName = $_POST['instituteName'];
$nameHindi = $_POST['nameHindi'];
$address = $_POST['address'];
$phoneNo = $_POST['phoneNo'];
$email = $_POST['email'];
$website = $_POST['website'];
$departments = $_POST['departments'];
$programs = $_POST['programs'];
$instituteHead = $_POST['instituteHead'];
$logoImage = $_POST['logoImage'];
$brandTagline = $_POST['brandTagline'];
$idSignatory = $_POST['idSignatory'];
$idAddressee = $_POST['idAddressee'];
$signImage = $_POST['signImage'];
$this->model->saveInstitute($instituteCode,$instituteName,$nameHindi,$address,$phoneNo,$email,$website,$departments,$programs,$instituteHead,$logoImage,$brandTagline,$idSignatory,$idAddressee,$signImage);
//$this->model->sqlLog();
$this->errorText = 'Institute record saved successfully.';
break;
case 'upper':
// enable record
$this->model->upperInstitute();
$this->errorText = 'Institute record moved up/left successfully.';
break;
case 'lower':
// disable record
$this->model->lowerInstitute();
$this->errorText = 'Institute record moved down/right successfully.';
break;
case 'enable':
// enable record
$this->model->enableInstitute();
$this->model->sqlLog();
$this->errorText = 'Institute record enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableInstitute();
$this->model->sqlLog();
$this->errorText = 'Institute record disabled successfully.';
break;
case 'delete':
// delete record
$this->model->deleteInstitute();
$this->model->sqlLog();
$this->errorText = 'Institute record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageBoard($action, $boardID) {
$this->model->tableID = 'erp_boards';
$this->model->tupleID = $boardID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
// save record
$boardCode = $_POST['boardCode'];
$boardName = $_POST['boardName'];
$boardLevel = $_POST['boardLevel'];
$address = $_POST['address'];
$this->model->saveBoard($boardCode,$boardName,$boardLevel,$address);
$this->model->sqlLog();
$this->errorText = 'Board record saved successfully.';
break;
case 'upper':
// move up/left side
$this->model->upperBoard();
$this->errorText = 'Board record moved up/left successfully.';
break;
case 'lower':
// move down/right side
$this->model->lowerBoard();
$this->errorText = 'Board record moved down/right successfully.';
break;
case 'enable':
// enable record
$this->model->enableBoard();
$this->errorText = 'Board and related records enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableBoard();
$this->errorText = 'Board and related records disabled successfully.';
break;
case 'delete':
// delete record
$this->model->deleteBoard();
$this->model->sqlLog();
$this->errorText = 'Board record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageModule($action, $moduleID) {
$this->model->tableID = 'erp_modules';
$this->model->tupleID = $moduleID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
// save record
$moduleName = $_POST['moduleName'];
$description = $_POST['description'];
$moduleIcon = $_POST['moduleIcon'];
$iconColor = $_POST['iconColor'];
$moduleDept = $_POST['moduleDept'];
$moduleAdmin = $_POST['moduleAdmin'];
$adminEmail = $_POST['adminEmail'];
$this->model->saveModule($moduleName,$description,$moduleIcon,$iconColor,$moduleDept,$moduleAdmin,$adminEmail);
$this->model->sqlLog();
$this->errorText = 'Module record saved successfully.';
break;
case 'upper':
// move up/left side
$this->model->upperModule();
$this->errorText = 'Module record moved up/left successfully.';
break;
case 'lower':
// move down/right side
$this->model->lowerModule();
$this->errorText = 'Module record moved down/right successfully.';
break;
case 'enable':
// enable record
$this->model->enableModule();
$this->errorText = 'Module and related records enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableModule();
$this->errorText = 'Module and related records disabled successfully.';
break;
case 'delete':
// delete record
$this->model->deleteModule();
$this->model->sqlLog();
$this->errorText = 'Module record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageApp($action, $appID) {
$this->model->tableID = 'erp_apps';
$this->model->tupleID = $appID;
$moduleID = $this->params[0];
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
//save record
$appName = $_POST['appName'];
$description = $_POST['description'];
$appCode = $_POST['appCode'];
$appURL = $_POST['appURL'];
$appIcon = $_POST['appIcon'];
$iconColor = $_POST['iconColor'];
$appDept = $_POST['appDept'];
$appAdmin = $_POST['appAdmin'];
$adminEmail = $_POST['adminEmail'];
$universal = $_POST['universal'];
$this->model->saveApp($moduleID,$appName,$description,$appCode,$appURL,$appIcon,$iconColor,$appDept,$appAdmin,$adminEmail,$universal);
$this->model->sqlLog();
$this->errorText = 'App record saved successfully.';
break;
case 'upper':
// move up/left side
$this->model->upperApp();
$this->errorText = 'App record moved up/left successfully.';
break;
case 'lower':
// move down/right side
$this->model->lowerApp();
$this->errorText = 'App record moved down/right successfully.';
break;
case 'enable':
// enable record
$this->model->enableApp();
$this->errorText = 'App and related records enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableApp();
$this->errorText = 'App and related records disabled successfully.';
break;
case 'delete':
//delete record
$this->model->deleteApp();
$this->model->sqlLog();
$this->errorText = 'App record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageMenu($action, $menuID) {
$this->model->tableID = 'erp_menus';
$this->model->tupleID = $menuID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
//save record
$appID = $_POST['appID'];
$interface = $_POST['interface'];
$parentID = $_POST['parentID'];
$menuName = $_POST['menuName'];
$description = $_POST['description'];
$menuURL = $_POST['menuURL'];
$menuIcon = $_POST['menuIcon'];
$menuHelp = $_POST['menuHelp'];
$protection = $_POST['protection'];
$this->model->saveMenu($appID,$interface,$parentID,$menuName,$description,$menuURL,$menuIcon,$menuHelp,$protection);
$this->model->sqlLog();
$this->errorText = 'Menu record saved successfully.';
break;
case 'upper':
// move up/left side
$this->model->upperMenu();
$this->errorText = 'Menu record moved up/left successfully.';
break;
case 'lower':
// move down/right side
$this->model->lowerMenu();
$this->errorText = 'Menu record moved down/right successfully.';
break;
case 'enable':
// enable record
$this->model->enableMenu();
$this->errorText = 'Menu and related records enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableMenu();
$this->errorText = 'Menu and related records disabled successfully.';
break;
case 'delete':
//delete record
$this->model->deleteMenu();
$this->model->sqlLog();
$this->errorText = 'Menu record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageGroup($action, $groupID) {
$this->model->tableID = 'erp_groups';
$this->model->tupleID = $groupID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
//save record
$groupName = $_POST['groupName'];
$description = $_POST['description'];
$dashboard = $_POST['dashboard'];
if (!$description) $description = $groupName;
if ($groupName) $this->model->saveGroup($groupName,$description,$dashboard);
$this->model->sqlLog();
$this->errorText = "Group record saved successfully.";
break;
case 'upper':
// move up/left side
$this->model->upperGroup();
$this->errorText = 'Group record moved up/left successfully.';
break;
case 'lower':
// move down/right side
$this->model->lowerGroup();
$this->errorText = 'Group record moved down/right successfully.';
break;
case 'enable':
// enable record
$this->model->enableGroup();
$this->errorText = 'Group and related records enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableGroup();
$this->errorText = 'Group and related records disabled successfully.';
break;
case 'delete':
//delete record
$this->model->deleteGroup();
$this->model->sqlLog();
$this->errorText = 'Group record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageGacl($action, $groupID) {
$this->model->tableID = 'erp_gacls';
$this->model->tupleID = $groupID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
case 'search':
break;
case 'save':
//save record
foreach ($_POST['aclID'] as $aclID) {
$i++;
$this->model->tableID = 'erp_gacls';
$this->model->tupleID = $aclID;
$menuID = $_POST["menuID$i"];
$aclRead = $_POST["aclRead$i"] ? 1 : 0;
$aclInsert = $_POST["aclInsert$i"] ? 1 : 0;
$aclUpdate = $_POST["aclUpdate$i"] ? 1 : 0;
$aclDelete = $_POST["aclDelete$i"] ? 1 : 0;
if ($aclRead || $aclInsert || $aclUpdate || $aclDelete) {
$this->model->saveGacl($groupID,$menuID,$aclRead,$aclInsert,$aclUpdate,$aclDelete);
$this->model->sqlLog();
} else if ($aclID) { // only in case of existing acl
$this->model->deleteGacl($aclID);
$this->model->sqlLog();
}
$rows = $this->model->listUsers($groupID);
foreach ($rows as $row) {
$userID = $row['userID'];
$data = $this->model->getUacl($userID, $menuID);
$this->model->tableID = 'erp_uacls';
$this->model->tupleID = ($data['aclID'] ? $data['aclID'] : 0);
if ($aclRead || $aclInsert || $aclUpdate || $aclDelete) {
$this->model->saveUacl($userID,$menuID,$aclRead,$aclInsert,$aclUpdate,$aclDelete);
} else if ($aclID) { // only in case of existing acl
$this->model->deleteUacl($data['aclID']);
}
}
}
$this->errorText = 'Group ACL record saved successfully.';
$this->model->tupleID = $groupID; // because it was set to aclID for sql log entry
break;
case 'filter':
//filter record
if ($this->filterText) {
$this->errorText = "ACL record filtered on " . strtoupper($this->filterText);
}
break;
}
return $this->model->tupleID;
}
public function manageUser($action, $userID) {
$this->model->tableID = 'erp_users';
$this->model->tupleID = $userID;
$groupID = $this->params[0];
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
//save record
$loginID = $_POST['loginID'];
$userName = $_POST['userName'];
$authMode = $_POST['authMode'];
$secretCode = $_POST['secretCode'];
$this->model->saveUser($loginID,$userName,$groupID,$authMode,$secretCode);
$this->model->sqlLog();
$this->errorText = "User record saved successfully.";
break;
case 'enable':
// enable record
$this->model->enableUser();
$this->model->sqlLog();
$this->errorText = 'User record enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableUser();
$this->model->sqlLog();
$this->errorText = 'User record disabled successfully.';
break;
case 'delete':
//delete record
$this->model->deleteUser();
$this->model->sqlLog();
$this->errorText = 'User record deleted successfully.';
break;
}
return $this->model->tupleID;
}
public function manageUacl($action, $userID) {
$this->model->tableID = 'erp_uacls';
$this->model->tupleID = $userID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
case 'search':
break;
case 'save':
//save record
foreach ($_POST['aclID'] as $aclID) {
$i++;
$this->model->tupleID = $aclID;
$menuID = $_POST["menuID$i"];
$aclRead = $_POST["aclRead$i"] ? 1 : 0;
$aclInsert = $_POST["aclInsert$i"] ? 1 : 0;
$aclUpdate = $_POST["aclUpdate$i"] ? 1 : 0;
$aclDelete = $_POST["aclDelete$i"] ? 1 : 0;
if ($aclRead || $aclInsert || $aclUpdate || $aclDelete) {
$this->model->saveUacl($userID,$menuID,$aclRead,$aclInsert,$aclUpdate,$aclDelete);
$this->model->sqlLog();
} else if ($aclID) {
$this->model->deleteUacl($aclID);
$this->model->sqlLog();
}
}
$this->errorText = 'User ACL record saved successfully.';
$this->model->tupleID = $userID; // because it was set to aclID for sql log entry
break;
case 'filter':
//filter record
if ($this->filterText) {
$this->errorText = "ACL record filtered on " . strtoupper($this->filterText);
}
break;
}
return $this->model->tupleID;
}
public function manageMessage($action, $messageID) {
$this->model->tableID = 'erp_messages';
$this->model->tupleID = $messageID;
switch ($action) {
case 'new':
case 'edit':
$this->editLock = '';
break;
case 'open':
case 'help':
case 'trash':
break;
case 'save':
// save record
$subject = $_POST['subject'];
$message = $_POST['message'];
$sender = $_POST['sender'];
$recipient = $_POST['recipient'];
$this->model->saveMessage($subject,$message,$sender,$recipient);
$this->model->sqlLog();
$this->errorText = 'Message record saved successfully.';
break;
case 'enable':
// enable record
$this->model->enableMessage();
$this->errorText = 'Message record enabled successfully.';
break;
case 'disable':
// disable record
$this->model->disableMessage();
$this->errorText = 'Message record disabled successfully.';
break;
case 'delete':
// delete record
$this->model->deleteMessage();
$this->model->sqlLog();
$this->errorText = 'Message record deleted successfully.';
break;
}
return $this->model->tupleID;
}
}
?>