diff --git a/workflow/engine/controllers/caseSchedulerProxy.php b/workflow/engine/controllers/caseSchedulerProxy.php index b81e945b8..99a0f948c 100755 --- a/workflow/engine/controllers/caseSchedulerProxy.php +++ b/workflow/engine/controllers/caseSchedulerProxy.php @@ -1,569 +1,691 @@ PRO_UID; - $EVN_UID = $params->EVN_UID; + function load ($params) + { + require_once "classes/model/Event.php"; + $PRO_UID = $params->PRO_UID; + $EVN_UID = $params->EVN_UID; - $oEvent = new Event(); - $oData = $oEvent->load($EVN_UID); - $sch_uid = $oData['EVN_ACTION']; + $oEvent = new Event(); + $oData = $oEvent->load( $EVN_UID ); + $sch_uid = $oData['EVN_ACTION']; - if ($sch_uid != ''){ - G::LoadClass('processMap'); - $oProcessMap = new processMap(new DBConnection); - $rows = $oProcessMap->caseNewSchedulerList($sch_uid); - if($rows['SCH_OPTION'] == '3') - { - $sch_start_day = explode('|',$rows['SCH_START_DAY']); - $count = count($sch_start_day); - switch($count){ - case 1: - $rows['SCH_START_DAY'] = $sch_start_day[0]; - break; - case 2: - $rows['SCH_START_DAY'] = $sch_start_day[0]; - $rows['SCH_START_DAY_OPT_2_WEEKS'] = $sch_start_day[1]; - break; - case 3: - $rows['SCH_START_DAY'] = $sch_start_day[0]; - $rows['SCH_START_DAY_OPT_2_WEEKS'] = $sch_start_day[1]; - $rows['SCH_START_DAY_OPT_2_DAYS_WEEK'] = $sch_start_day[2]; - break; - } - } - if($rows['SCH_START_DATE'] != '') - { - $sch_str_dt = explode(' ',$rows['SCH_START_DATE']); - $rows['SCH_START_DATE'] = $sch_str_dt[0]; - } - if($rows['SCH_END_DATE'] != '') - { - $sch_str_dt = explode(' ',$rows['SCH_END_DATE']); - $rows['SCH_END_DATE'] = $sch_str_dt[0]; - } - $this->success = true; - $this->data = $rows; - }else{ - $this->success = false; - } - } - - function delete($params){ - require_once 'classes/model/CaseScheduler.php'; - require_once 'classes/model/Event.php'; - $SCH_UID = $params->SCH_UID; - $EVN_UID = $params->EVN_UID; - $oCaseScheduler = new CaseScheduler(); - $oCaseScheduler->remove($SCH_UID); - $oEvent = new Event(); - $editE = array(); - $editE['EVN_UID'] = $EVN_UID; - $editE['EVN_ACTION'] = ''; - $oEvent->update($editE); - - $this->success = true; - $this->msg = G::LoadTranslation('ID_SCHEDULER_SUCCESS_DELETE'); - } - - function changeStatus($params){ - require_once 'classes/model/CaseScheduler.php'; - $SCH_UID = $params->SCH_UID; - $oCaseScheduler = new CaseScheduler(); - $oCaseScheduler->changeStatus ($SCH_UID); - $oCaseScheduler->load($SCH_UID); - $this->success = true; - $this->SCH_STATUS = $oCaseScheduler->getSchState(); - $this->msg = G::LoadTranslation('ID_SCHEDULER_SUCCESS_CHANGE_STATUS'); - } - -function checkCredentials($params){ - require_once 'classes/model/Event.php'; - require_once 'classes/model/Users.php'; - require_once 'classes/model/TaskUser.php'; - require_once 'classes/model/GroupUser.php'; - $sPRO_UID = $params->PRO_UID; - $sEVN_UID = $params->EVN_UID; - $sWS_USER = trim($params->WS_USER); - $sWS_PASS = trim($params->WS_PASS); - - if (G::is_https ()) - $http = 'https://'; - else - $http = 'http://'; - - $endpoint = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/wsdl2'; - @$client = new SoapClient ( $endpoint ); - - $user = $sWS_USER; - $pass = $sWS_PASS; - - $parameters = array ('userid' => $user, 'password' => $pass ); - $result = $client->__SoapCall ( 'login', array ($parameters) ); - - $fields ['status_code'] = $result->status_code; - $fields ['message'] = 'ProcessMaker WebService version: ' . $result->version . "\n" . $result->message; - $fields ['version'] = $result->version; - $fields ['time_stamp'] = $result->timestamp; - $messageCode = true; - $message = $result->message; - - G::LoadClass ( 'Task' ); - //G::LoadClass ( 'Event' ); - G::LoadClass ( 'User' ); - G::LoadClass ( 'TaskUser' ); - G::LoadClass ( 'Groupwf' ); - - $event = new Event(); - $event->load($sEVN_UID); - $sTASKS = $event->getEvnTasUidTo(); - - $task = new Task(); - $task->load($sTASKS); - $sTASKS_SEL = $task->getTasTitle(); - - if(!class_exists('GroupUser')) { - G::LoadClass ( 'GroupUser' ); - } - // if the user has been authenticated, then check if has the rights or - // permissions to create the webentry - if ($result->status_code == 0) { - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(UsersPeer::USR_UID); - $oCriteria->addSelectColumn(TaskUserPeer::USR_UID); - $oCriteria->addSelectColumn(TaskUserPeer::TAS_UID); - $oCriteria->addJoin(TaskUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN); - $oCriteria->add(TaskUserPeer::TAS_UID, $sTASKS); - $oCriteria->add(UsersPeer::USR_USERNAME, $sWS_USER); - //$oCriteria->add(TaskUserPeer::TU_RELATION,1); - $userIsAssigned = TaskUserPeer::doCount($oCriteria); - // if the user is not assigned directly, maybe a have the task a group with the user - if($userIsAssigned<1) { - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(UsersPeer::USR_UID); - $oCriteria->addJoin(UsersPeer::USR_UID, GroupUserPeer::USR_UID, Criteria::LEFT_JOIN); - $oCriteria->addJoin(GroupUserPeer::GRP_UID, TaskUserPeer::USR_UID, Criteria::LEFT_JOIN); - $oCriteria->add(TaskUserPeer::TAS_UID, $sTASKS); - $oCriteria->add(UsersPeer::USR_USERNAME, $sWS_USER); - $userIsAssigned = GroupUserPeer::doCount($oCriteria); - if (!($userIsAssigned>=1)) { - $messageCode = false; - $message = "The User \"".$sWS_USER."\" doesn't have the task \"".$sTASKS_SEL."\" assigned."; - } - } - - } else { - $messageCode = false; - } - - $this->success = $messageCode; - $this->msg = $message; - } - - function save($params){ - require_once 'classes/model/CaseScheduler.php'; - $oCaseScheduler = new CaseScheduler(); - - $aData['SCH_UID'] = G::generateUniqueID(); - $aData['SCH_NAME'] = $params->fDescription; //$_POST['form']['SCH_NAME']; - $aData['SCH_DEL_USER_NAME'] = $params->fUser; //$_POST['form']['SCH_USER_NAME']; - $aData['SCH_DEL_USER_PASS'] = md5($params->fPassword); - $aData['SCH_DEL_USER_UID'] = $params->usr_uid; //$_POST['form']['SCH_USER_UID']; - $aData['PRO_UID'] = $params->pro_uid; //$_POST['form']['PRO_UID']; - $aData['TAS_UID'] = $params->tas_uid; //$_POST['form']['TAS_UID']; - - $aData['SCH_STATE'] = 'ACTIVE'; - $aData['SCH_LAST_STATE'] = 'CREATED'; // 'ACTIVE'; - $aData['USR_UID'] = $_SESSION['USER_LOGGED']; - - $sOption = $params->fType; //$_POST['form']['SCH_OPTION']; - - switch($sOption){ - case 'Daily' : $sOption = '1'; break; - case 'Weekly' : $sOption = '2'; break; - case 'Monthly' : $sOption = '3'; break; - default : $sOption = '4'; break; - } - - $aData['SCH_OPTION'] = $sOption; - -// if ($_POST['form']['SCH_START_DATE']!=''){ -// $sDateTmp = $_POST['form']['SCH_START_DATE']; -// } else { -// $sDateTmp = date('Y-m-d'); -// } - - $sDateTmp = $params->SCH_START_DATE; - $sTimeTmp = $params->SCH_START_TIME; //$_POST['form']['SCH_START_TIME']; - - $aData['SCH_START_TIME'] = date('Y-m-d', strtotime($sDateTmp)) . ' ' . date('H:i:s', strtotime($sTimeTmp)); - $aData['SCH_START_DATE'] = date('Y-m-d', strtotime($sDateTmp)) . ' ' . date('H:i:s', strtotime($sTimeTmp)); - - //g::pr($aData); - - $nActualTime = $sTimeTmp; //date("Y-m-d H:i:s"); // time(); - //$nActualDate = date("Y-m-d H:i:s"); - - $sValue = ''; - $sDaysPerformTask = ''; - $sWeeks = ''; - $sMonths = ''; - $sMonths = ''; - $sStartDay = ''; - $nSW = 0; - - - switch($sOption){ - case '1' : // Option 1 - $sValue = isset($params->SCH_DAYS_PERFORM_TASK)? $params->SCH_DAYS_PERFORM_TASK : '1'; //$_POST['form']['SCH_DAYS_PERFORM_TASK']; - switch($sValue){ - case '1' : $aData['SCH_DAYS_PERFORM_TASK'] = $sValue . '|1'; - break; - case '2' : - $aData['SCH_OPTION'] = '2'; - $aData['SCH_EVERY_DAYS'] = '1'; - $aData['SCH_WEEK_DAYS'] = '1|2|3|4|5|'; - break; - case '3' : // Every [n] Days - $sDaysPerformTask = $params->SCH_DAYS_PERFORM_TASK_OPT_3; - $aData['SCH_DAYS_PERFORM_TASK'] = $params->SCH_DAYS_PERFORM_TASK . '|' . $params->SCH_DAYS_PERFORM_TASK_OPT_3; - break; - } - break; - - case '2' : // If the option is zero, set by default 1 - $sWeeks = ''; - if (isset($params->W1)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '1'; - } - if (isset($params->W2)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '2'; - } - if (isset($params->W3)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '3'; - } - if (isset($params->W4)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '4'; - } - if (isset($params->W5)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '5'; - } - if (isset($params->W6)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '6'; - } - if (isset($params->W7)){ - if ($sWeeks != '') $sWeeks .= '|'; - $sWeeks .= '7'; - } - $sStartTime = $params->SCH_START_TIME; - $aData['SCH_WEEK_DAYS'] = $sWeeks; - $aData['SCH_START_DAY'] = ''; // - break; - case '3' : - $nStartDay = $params->SCH_START_DAY; - if ($nStartDay=='Day of Month') $nStartDay = 1; - if ($nStartDay=='The Day') $nStartDay = 2; - if($nStartDay == 1){ - $aData['SCH_START_DAY'] = $nStartDay . '|' . $params->SCH_START_DAY_OPT_1; + if ($sch_uid != '') { + G::LoadClass( 'processMap' ); + $oProcessMap = new processMap( new DBConnection() ); + $rows = $oProcessMap->caseNewSchedulerList( $sch_uid ); + if ($rows['SCH_OPTION'] == '3') { + $sch_start_day = explode( '|', $rows['SCH_START_DAY'] ); + $count = count( $sch_start_day ); + switch ($count) { + case 1: + $rows['SCH_START_DAY'] = $sch_start_day[0]; + break; + case 2: + $rows['SCH_START_DAY'] = $sch_start_day[0]; + $rows['SCH_START_DAY_OPT_2_WEEKS'] = $sch_start_day[1]; + break; + case 3: + $rows['SCH_START_DAY'] = $sch_start_day[0]; + $rows['SCH_START_DAY_OPT_2_WEEKS'] = $sch_start_day[1]; + $rows['SCH_START_DAY_OPT_2_DAYS_WEEK'] = $sch_start_day[2]; + break; + } + } + if ($rows['SCH_START_DATE'] != '') { + $sch_str_dt = explode( ' ', $rows['SCH_START_DATE'] ); + $rows['SCH_START_DATE'] = $sch_str_dt[0]; + } + if ($rows['SCH_END_DATE'] != '') { + $sch_str_dt = explode( ' ', $rows['SCH_END_DATE'] ); + $rows['SCH_END_DATE'] = $sch_str_dt[0]; + } + $this->success = true; + $this->data = $rows; } else { - $opt2weeks = $params->SCH_START_DAY_OPT_2_WEEKS; - switch($opt2weeks){ - case 'First': $opt2weeks = 1; break; - case 'Second': $opt2weeks = 2; break; - case 'Third': $opt2weeks = 3; break; - case 'Fourth': $opt2weeks = 4; break; - case 'Last': $opt2weeks = 5; break; - } - $opt2days = $params->SCH_START_DAY_OPT_2_DAYS_WEEK; - switch($opt2days){ - case 'Monday': $opt2days = 1; break; - case 'Tuesday': $opt2days = 2; break; - case 'Wednesday': $opt2days = 3; break; - case 'Thursday': $opt2days = 4; break; - case 'Friday': $opt2days = 5; break; - case 'Saturday': $opt2days = 6; break; - case 'Sunday': $opt2days = 7; break; - } - $aData['SCH_START_DAY'] = $nStartDay . '|' . $opt2weeks . '|' . $opt2days; + $this->success = false; } - + } + + function delete ($params) + { + require_once 'classes/model/CaseScheduler.php'; + require_once 'classes/model/Event.php'; + $SCH_UID = $params->SCH_UID; + $EVN_UID = $params->EVN_UID; + $oCaseScheduler = new CaseScheduler(); + $oCaseScheduler->remove( $SCH_UID ); + $oEvent = new Event(); + $editE = array (); + $editE['EVN_UID'] = $EVN_UID; + $editE['EVN_ACTION'] = ''; + $oEvent->update( $editE ); + + $this->success = true; + $this->msg = G::LoadTranslation( 'ID_SCHEDULER_SUCCESS_DELETE' ); + } + + function changeStatus ($params) + { + require_once 'classes/model/CaseScheduler.php'; + $SCH_UID = $params->SCH_UID; + $oCaseScheduler = new CaseScheduler(); + $oCaseScheduler->changeStatus( $SCH_UID ); + $oCaseScheduler->load( $SCH_UID ); + $this->success = true; + $this->SCH_STATUS = $oCaseScheduler->getSchState(); + $this->msg = G::LoadTranslation( 'ID_SCHEDULER_SUCCESS_CHANGE_STATUS' ); + } + + function checkCredentials ($params) + { + require_once 'classes/model/Event.php'; + require_once 'classes/model/Users.php'; + require_once 'classes/model/TaskUser.php'; + require_once 'classes/model/GroupUser.php'; + $sPRO_UID = $params->PRO_UID; + $sEVN_UID = $params->EVN_UID; + $sWS_USER = trim( $params->WS_USER ); + $sWS_PASS = trim( $params->WS_PASS ); + + if (G::is_https()) { + $http = 'https://'; + } else { + $http = 'http://'; + } + $endpoint = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/wsdl2'; + @$client = new SoapClient( $endpoint ); + + $user = $sWS_USER; + $pass = $sWS_PASS; + + $parameters = array ('userid' => $user,'password' => $pass + ); + $result = $client->__SoapCall( 'login', array ($parameters + ) ); + + $fields['status_code'] = $result->status_code; + $fields['message'] = 'ProcessMaker WebService version: ' . $result->version . "\n" . $result->message; + $fields['version'] = $result->version; + $fields['time_stamp'] = $result->timestamp; + $messageCode = true; + $message = $result->message; + + G::LoadClass( 'Task' ); + //G::LoadClass ( 'Event' ); + G::LoadClass( 'User' ); + G::LoadClass( 'TaskUser' ); + G::LoadClass( 'Groupwf' ); + + $event = new Event(); + $event->load( $sEVN_UID ); + $sTASKS = $event->getEvnTasUidTo(); + + $task = new Task(); + $task->load( $sTASKS ); + $sTASKS_SEL = $task->getTasTitle(); + + if (! class_exists( 'GroupUser' )) { + G::LoadClass( 'GroupUser' ); + } + // if the user has been authenticated, then check if has the rights or + // permissions to create the webentry + if ($result->status_code == 0) { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( UsersPeer::USR_UID ); + $oCriteria->addSelectColumn( TaskUserPeer::USR_UID ); + $oCriteria->addSelectColumn( TaskUserPeer::TAS_UID ); + $oCriteria->addJoin( TaskUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN ); + $oCriteria->add( TaskUserPeer::TAS_UID, $sTASKS ); + $oCriteria->add( UsersPeer::USR_USERNAME, $sWS_USER ); + //$oCriteria->add(TaskUserPeer::TU_RELATION,1); + $userIsAssigned = TaskUserPeer::doCount( $oCriteria ); + // if the user is not assigned directly, maybe a have the task a group with the user + if ($userIsAssigned < 1) { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( UsersPeer::USR_UID ); + $oCriteria->addJoin( UsersPeer::USR_UID, GroupUserPeer::USR_UID, Criteria::LEFT_JOIN ); + $oCriteria->addJoin( GroupUserPeer::GRP_UID, TaskUserPeer::USR_UID, Criteria::LEFT_JOIN ); + $oCriteria->add( TaskUserPeer::TAS_UID, $sTASKS ); + $oCriteria->add( UsersPeer::USR_USERNAME, $sWS_USER ); + $userIsAssigned = GroupUserPeer::doCount( $oCriteria ); + if (! ($userIsAssigned >= 1)) { + $messageCode = false; + $message = "The User \"" . $sWS_USER . "\" doesn't have the task \"" . $sTASKS_SEL . "\" assigned."; + } + } + + } else { + $messageCode = false; + } + + $this->success = $messageCode; + $this->msg = $message; + } + + function save ($params) + { + require_once 'classes/model/CaseScheduler.php'; + $oCaseScheduler = new CaseScheduler(); + + $aData['SCH_UID'] = G::generateUniqueID(); + $aData['SCH_NAME'] = $params->fDescription; //$_POST['form']['SCH_NAME']; + $aData['SCH_DEL_USER_NAME'] = $params->fUser; //$_POST['form']['SCH_USER_NAME']; + $aData['SCH_DEL_USER_PASS'] = md5( $params->fPassword ); + $aData['SCH_DEL_USER_UID'] = $params->usr_uid; //$_POST['form']['SCH_USER_UID']; + $aData['PRO_UID'] = $params->pro_uid; //$_POST['form']['PRO_UID']; + $aData['TAS_UID'] = $params->tas_uid; //$_POST['form']['TAS_UID']; + + + $aData['SCH_STATE'] = 'ACTIVE'; + $aData['SCH_LAST_STATE'] = 'CREATED'; // 'ACTIVE'; + $aData['USR_UID'] = $_SESSION['USER_LOGGED']; + + $sOption = $params->fType; //$_POST['form']['SCH_OPTION']; + + switch ($sOption) { + case 'Daily': + $sOption = '1'; + break; + case 'Weekly': + $sOption = '2'; + break; + case 'Monthly': + $sOption = '3'; + break; + default: + $sOption = '4'; + break; + } + + $aData['SCH_OPTION'] = $sOption; + + // if ($_POST['form']['SCH_START_DATE']!=''){ + // $sDateTmp = $_POST['form']['SCH_START_DATE']; + // } else { + // $sDateTmp = date('Y-m-d'); + // } + + + $sDateTmp = $params->SCH_START_DATE; + $sTimeTmp = $params->SCH_START_TIME; //$_POST['form']['SCH_START_TIME']; + + + $aData['SCH_START_TIME'] = date( 'Y-m-d', strtotime( $sDateTmp ) ) . ' ' . date( 'H:i:s', strtotime( $sTimeTmp ) ); + $aData['SCH_START_DATE'] = date( 'Y-m-d', strtotime( $sDateTmp ) ) . ' ' . date( 'H:i:s', strtotime( $sTimeTmp ) ); + + //g::pr($aData); + + + $nActualTime = $sTimeTmp; //date("Y-m-d H:i:s"); // time(); + //$nActualDate = date("Y-m-d H:i:s"); + + + $sValue = ''; + $sDaysPerformTask = ''; + $sWeeks = ''; $sMonths = ''; - if (isset($params->M1)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '1'; - } - if (isset($params->M2)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '2'; - } - if (isset($params->M3)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '3'; - } - if (isset($params->M4)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '4'; - } - if (isset($params->M5)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '5'; - } - if (isset($params->M6)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '6'; - } - if (isset($params->M7)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '7'; - } - if (isset($params->M8)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '8'; - } - if (isset($params->M9)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '9'; - } - if (isset($params->M10)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '10'; - } - if (isset($params->M11)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '11'; - } - if (isset($params->M12)){ - if ($sMonths != '') $sMonths .= '|'; - $sMonths .= '12'; - } -// if(!empty($params->SCH_MONTHS)){ -// $aMonths = $params->SCH_MONTHS; -// foreach($aMonths as $value) { -// $sMonths = $sMonths . $value . '|' ; -// } -// } -// if(!empty($params->SCH_MONTHS_2)){ -// $aMonths2 = $params->SCH_MONTHS_2; -// foreach($aMonths2 as $value) { -// $sMonths = $sMonths . $value . '|' ; -// } -// } -// if(!empty($params->SCH_MONTHS_3)){ -// $aMonths3 = $params->SCH_MONTHS_3; -// foreach($aMonths3 as $value) { -// $sMonths = $sMonths . $value . '|' ; -// } -// } - $aData['SCH_MONTHS'] = $sMonths; - $sStartDay = $aData['SCH_START_DAY']; - $sValue = $nStartDay; - break; - + $sMonths = ''; + $sStartDay = ''; + $nSW = 0; + + switch ($sOption) { + case '1': // Option 1 + $sValue = isset( $params->SCH_DAYS_PERFORM_TASK ) ? $params->SCH_DAYS_PERFORM_TASK : '1'; //$_POST['form']['SCH_DAYS_PERFORM_TASK']; + switch ($sValue) { + case '1': + $aData['SCH_DAYS_PERFORM_TASK'] = $sValue . '|1'; + break; + case '2': + $aData['SCH_OPTION'] = '2'; + $aData['SCH_EVERY_DAYS'] = '1'; + $aData['SCH_WEEK_DAYS'] = '1|2|3|4|5|'; + break; + case '3': // Every [n] Days + $sDaysPerformTask = $params->SCH_DAYS_PERFORM_TASK_OPT_3; + $aData['SCH_DAYS_PERFORM_TASK'] = $params->SCH_DAYS_PERFORM_TASK . '|' . $params->SCH_DAYS_PERFORM_TASK_OPT_3; + break; + } + break; + case '2': // If the option is zero, set by default 1 + $sWeeks = ''; + if (isset( $params->W1 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '1'; + } + if (isset( $params->W2 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '2'; + } + if (isset( $params->W3 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '3'; + } + if (isset( $params->W4 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '4'; + } + if (isset( $params->W5 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '5'; + } + if (isset( $params->W6 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '6'; + } + if (isset( $params->W7 )) { + if ($sWeeks != '') { + $sWeeks .= '|'; + } + $sWeeks .= '7'; + } + $sStartTime = $params->SCH_START_TIME; + $aData['SCH_WEEK_DAYS'] = $sWeeks; + $aData['SCH_START_DAY'] = ''; // + break; + case '3': + $nStartDay = $params->SCH_START_DAY; + if ($nStartDay == 'Day of Month') { + $nStartDay = 1; + } + if ($nStartDay == 'The Day') { + $nStartDay = 2; + } + if ($nStartDay == 1) { + $aData['SCH_START_DAY'] = $nStartDay . '|' . $params->SCH_START_DAY_OPT_1; + } else { + $opt2weeks = $params->SCH_START_DAY_OPT_2_WEEKS; + switch ($opt2weeks) { + case 'First': + $opt2weeks = 1; + break; + case 'Second': + $opt2weeks = 2; + break; + case 'Third': + $opt2weeks = 3; + break; + case 'Fourth': + $opt2weeks = 4; + break; + case 'Last': + $opt2weeks = 5; + break; + } + $opt2days = $params->SCH_START_DAY_OPT_2_DAYS_WEEK; + switch ($opt2days) { + case 'Monday': + $opt2days = 1; + break; + case 'Tuesday': + $opt2days = 2; + break; + case 'Wednesday': + $opt2days = 3; + break; + case 'Thursday': + $opt2days = 4; + break; + case 'Friday': + $opt2days = 5; + break; + case 'Saturday': + $opt2days = 6; + break; + case 'Sunday': + $opt2days = 7; + break; + } + $aData['SCH_START_DAY'] = $nStartDay . '|' . $opt2weeks . '|' . $opt2days; + } + + $sMonths = ''; + if (isset( $params->M1 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '1'; + } + if (isset( $params->M2 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '2'; + } + if (isset( $params->M3 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '3'; + } + if (isset( $params->M4 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '4'; + } + if (isset( $params->M5 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '5'; + } + if (isset( $params->M6 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '6'; + } + if (isset( $params->M7 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '7'; + } + if (isset( $params->M8 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '8'; + } + if (isset( $params->M9 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '9'; + } + if (isset( $params->M10 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '10'; + } + if (isset( $params->M11 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '11'; + } + if (isset( $params->M12 )) { + if ($sMonths != '') { + $sMonths .= '|'; + } + $sMonths .= '12'; + } + // if(!empty($params->SCH_MONTHS)){ + // $aMonths = $params->SCH_MONTHS; + // foreach($aMonths as $value) { + // $sMonths = $sMonths . $value . '|' ; + // } + // } + // if(!empty($params->SCH_MONTHS_2)){ + // $aMonths2 = $params->SCH_MONTHS_2; + // foreach($aMonths2 as $value) { + // $sMonths = $sMonths . $value . '|' ; + // } + // } + // if(!empty($params->SCH_MONTHS_3)){ + // $aMonths3 = $params->SCH_MONTHS_3; + // foreach($aMonths3 as $value) { + // $sMonths = $sMonths . $value . '|' ; + // } + // } + $aData['SCH_MONTHS'] = $sMonths; + $sStartDay = $aData['SCH_START_DAY']; + $sValue = $nStartDay; + break; - } - if(($sOption!='1') && ($sOption!='4')) { - if ($sStartDay==''){ - $sStartDay = date('Y-m-d'); - } - // echo $sOption."*". $sValue."*". $nActualTime."*". $sDaysPerformTask."*". $sWeeks."*". $sStartDay ."*". $sMonths."
"; - $dCurrentDay = date("d"); - $dCurrentMonth = date("m"); - $aStartDay = explode( "|" , $aData['SCH_START_DAY'] ); - if($sOption=='3'&&$aStartDay[0]=='1'){ - $monthsArray = explode("|",$sMonths); - foreach ($monthsArray as $row){ - if ( $dCurrentMonth == $row && $dCurrentDay<$aStartDay[1] ){ - $startTime = $params->SCH_START_TIME.":00"; - $aData['SCH_TIME_NEXT_RUN'] = date('Y') . '-' . $row . '-' . $aStartDay[1] . ' ' . $startTime; - break; - } else { - $aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun($sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp); - } } - } else { - $aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun($sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp); - } - // print_r ($aData['SCH_TIME_NEXT_RUN']); - // die; - } else { - if ($sOption=='4'){ - $aData['SCH_END_DATE'] = $aData['SCH_START_TIME']; - } - $aData['SCH_TIME_NEXT_RUN'] = $aData['SCH_START_TIME']; - } + if (($sOption != '1') && ($sOption != '4')) { + if ($sStartDay == '') { + $sStartDay = date( 'Y-m-d' ); + } + // echo $sOption."*". $sValue."*". $nActualTime."*". $sDaysPerformTask."*". $sWeeks."*". $sStartDay ."*". $sMonths."
"; + $dCurrentDay = date( "d" ); + $dCurrentMonth = date( "m" ); + $aStartDay = explode( "|", $aData['SCH_START_DAY'] ); + if ($sOption == '3' && $aStartDay[0] == '1') { + $monthsArray = explode( "|", $sMonths ); + foreach ($monthsArray as $row) { + if ($dCurrentMonth == $row && $dCurrentDay < $aStartDay[1]) { + $startTime = $params->SCH_START_TIME . ":00"; + $aData['SCH_TIME_NEXT_RUN'] = date( 'Y' ) . '-' . $row . '-' . $aStartDay[1] . ' ' . $startTime; + break; + } else { + $aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun( $sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp ); + } + } + } else { + $aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun( $sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp ); + } + // print_r ($aData['SCH_TIME_NEXT_RUN']); + // die; + } else { + if ($sOption == '4') { + $aData['SCH_END_DATE'] = $aData['SCH_START_TIME']; + } + $aData['SCH_TIME_NEXT_RUN'] = $aData['SCH_START_TIME']; + } - if (isset($params->SCH_END_DATE)){ - if(trim($params->SCH_END_DATE)!=''){ - $aData['SCH_END_DATE'] = $params->SCH_END_DATE; - } - } + if (isset( $params->SCH_END_DATE )) { + if (trim( $params->SCH_END_DATE ) != '') { + $aData['SCH_END_DATE'] = $params->SCH_END_DATE; + } + } - if(!empty($params->SCH_REPEAT_TASK_CHK)){ - $nOptEvery = $params->SCH_REPEAT_EVERY_OPT; - if($nOptEvery ==2) - $aData['SCH_REPEAT_EVERY'] = $params->SCH_REPEAT_EVERY_OPT * 60; - else - $aData['SCH_REPEAT_EVERY'] = $params->SCH_REPEAT_EVERY_OPT; + if (! empty( $params->SCH_REPEAT_TASK_CHK )) { + $nOptEvery = $params->SCH_REPEAT_EVERY_OPT; + if ($nOptEvery == 2) { + $aData['SCH_REPEAT_EVERY'] = $params->SCH_REPEAT_EVERY_OPT * 60; + } else { + $aData['SCH_REPEAT_EVERY'] = $params->SCH_REPEAT_EVERY_OPT; + } + } + + if ((isset( $_POST['form']['CASE_SH_PLUGIN_UID'] )) && ($_POST['form']['CASE_SH_PLUGIN_UID'] != "")) { + $aData['CASE_SH_PLUGIN_UID'] = $_POST['form']['CASE_SH_PLUGIN_UID']; + } + //$aData['SCH_END_DATE'] = "2020-12-30"; + //g::pr($aData); + $sch_uid = $params->sch_uid; + if ($sch_uid != '') { + $aData['SCH_UID'] = $sch_uid; + $oCaseScheduler->Update( $aData ); + $sw_update = true; + } else { + $oCaseScheduler->create( $aData ); + $sch_uid = $oCaseScheduler->getSchUid(); + $sw_update = false; + } + + if ((isset( $_POST['form']['CASE_SH_PLUGIN_UID'] )) && ($_POST['form']['CASE_SH_PLUGIN_UID'] != "")) { + $params = explode( "--", $_REQUEST['form']['CASE_SH_PLUGIN_UID'] ); + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + $activePluginsForCaseScheduler = $oPluginRegistry->getCaseSchedulerPlugins(); + + foreach ($activePluginsForCaseScheduler as $key => $caseSchedulerPluginDetail) { + if (($caseSchedulerPluginDetail->sNamespace == $params[0]) && ($caseSchedulerPluginDetail->sActionId == $params[1])) { + $caseSchedulerSelected = $caseSchedulerPluginDetail; + } + } + if ((isset( $caseSchedulerSelected )) && (is_object( $caseSchedulerSelected ))) { + //Save the form + $oData = $_POST['pluginFields']; + $oData['SCH_UID'] = $aData['SCH_UID']; + $oPluginRegistry->executeMethod( $caseSchedulerPluginDetail->sNamespace, $caseSchedulerPluginDetail->sActionSave, $oData ); + } + } + + //Added by Qennix + //Update Start Time Event in BPMN + require_once 'classes/model/Event.php'; + require_once 'classes/model/Task.php'; + + $oTask = new Task(); + $oTask->load( $params->tas_uid ); + $evn_uid = $oTask->getStartingEvent(); + $tas_name = $oTask->getTasTitle(); + $event = new Event(); + $editEvent = array (); + $editEvent['EVN_UID'] = $evn_uid; + $editEvent['EVN_ACTION'] = $sch_uid; + $event->update( $editEvent ); + //End Adding - } + $sch = new CaseScheduler(); + $sch->load( $sch_uid ); - if((isset($_POST['form']['CASE_SH_PLUGIN_UID']))&&($_POST['form']['CASE_SH_PLUGIN_UID']!="")){ - $aData['CASE_SH_PLUGIN_UID'] = $_POST['form']['CASE_SH_PLUGIN_UID']; - } - //$aData['SCH_END_DATE'] = "2020-12-30"; - //g::pr($aData); - $sch_uid = $params->sch_uid; - if ($sch_uid !=''){ - $aData['SCH_UID'] = $sch_uid; - $oCaseScheduler->Update($aData); - $sw_update = true; - }else{ - $oCaseScheduler->create($aData); - $sch_uid = $oCaseScheduler->getSchUid(); - $sw_update = false; - } - - if((isset($_POST['form']['CASE_SH_PLUGIN_UID']))&&($_POST['form']['CASE_SH_PLUGIN_UID']!="")){ - $params=explode("--",$_REQUEST ['form']['CASE_SH_PLUGIN_UID']); - $oPluginRegistry =& PMPluginRegistry::getSingleton(); - $activePluginsForCaseScheduler=$oPluginRegistry->getCaseSchedulerPlugins(); - - foreach($activePluginsForCaseScheduler as $key => $caseSchedulerPluginDetail){ - if(($caseSchedulerPluginDetail->sNamespace==$params[0])&&($caseSchedulerPluginDetail->sActionId==$params[1])){ - $caseSchedulerSelected=$caseSchedulerPluginDetail; - + $this->success = true; + $this->SCH_UID = $sch_uid; + $this->NEXT = $sch->getSchTimeNextRun(); + $this->DESCRIPTION = $sch->getSchName(); + $this->TAS_NAME = $tas_name; + if ($sw_update) { + $this->msg = G::LoadTranslation( 'ID_SCHEDULER_SUCCESS_UPDATE' ); + } else { + $this->msg = G::LoadTranslation( 'ID_SCHEDULER_SUCCESS_NEW' ); } - } - if((isset($caseSchedulerSelected))&&(is_object($caseSchedulerSelected))){ - //Save the form - $oData=$_POST['pluginFields']; - $oData['SCH_UID'] =$aData['SCH_UID']; - $oPluginRegistry->executeMethod( $caseSchedulerPluginDetail->sNamespace, $caseSchedulerPluginDetail->sActionSave, $oData ); - } } - //Added by Qennix - //Update Start Time Event in BPMN - require_once 'classes/model/Event.php'; - require_once 'classes/model/Task.php'; + function loadCS ($params) + { + require_once 'classes/model/CaseScheduler.php'; + $SCH_UID = $params->SCH_UID; + $oCaseScheduler = new CaseScheduler(); + $data = $oCaseScheduler->load( $SCH_UID ); + $start_date = $data['SCH_START_DATE']; + $start_date = date( 'Y-m-d', strtotime( $start_date ) ); + $data['START_DATE'] = $start_date; + $end_date = $data['SCH_END_DATE']; + if ($end_date != '') { + $end_date = date( 'Y-m-d', strtotime( $end_date ) ); + } + $data['END_DATE'] = $end_date; + $exec_time = $data['SCH_START_TIME']; + $exec_time = date( 'H:i', strtotime( $exec_time ) ); + $data['EXEC_TIME'] = $exec_time; - $oTask = new Task(); - $oTask->load($params->tas_uid); - $evn_uid = $oTask->getStartingEvent(); - $tas_name = $oTask->getTasTitle(); - $event = new Event(); - $editEvent = array(); - $editEvent['EVN_UID'] = $evn_uid; - $editEvent['EVN_ACTION'] = $sch_uid; - $event->update($editEvent); - //End Adding - - $sch = new CaseScheduler(); - $sch->load($sch_uid); + $weeks = $data['SCH_WEEK_DAYS']; + $week = explode( '|', $weeks ); + $w1 = $w2 = $w3 = $w4 = $w5 = $w6 = $w7 = false; + foreach ($week as $w) { + switch ($w) { + case 1: + $w1 = true; + break; + case 2: + $w2 = true; + break; + case 3: + $w3 = true; + break; + case 4: + $w4 = true; + break; + case 5: + $w5 = true; + break; + case 6: + $w6 = true; + break; + case 7: + $w7 = true; + break; + } + } + $data['W1'] = $w1; + $data['W2'] = $w2; + $data['W3'] = $w3; + $data['W4'] = $w4; + $data['W5'] = $w5; + $data['W6'] = $w6; + $data['W7'] = $w7; - $this->success = true; - $this->SCH_UID = $sch_uid; - $this->NEXT = $sch->getSchTimeNextRun(); - $this->DESCRIPTION = $sch->getSchName(); - $this->TAS_NAME = $tas_name; - if ($sw_update) - $this->msg = G::LoadTranslation('ID_SCHEDULER_SUCCESS_UPDATE'); - else - $this->msg = G::LoadTranslation('ID_SCHEDULER_SUCCESS_NEW'); - } - - function loadCS($params){ - require_once 'classes/model/CaseScheduler.php'; - $SCH_UID = $params->SCH_UID; - $oCaseScheduler = new CaseScheduler(); - $data = $oCaseScheduler->load($SCH_UID); - $start_date = $data['SCH_START_DATE']; - $start_date = date('Y-m-d', strtotime($start_date)); - $data['START_DATE'] = $start_date; - $end_date = $data['SCH_END_DATE']; - if ($end_date != ''){ - $end_date = date('Y-m-d',strtotime($end_date)); - } - $data['END_DATE'] = $end_date; - $exec_time = $data['SCH_START_TIME']; - $exec_time = date('H:i',strtotime($exec_time)); - $data['EXEC_TIME'] = $exec_time; - - $weeks = $data['SCH_WEEK_DAYS']; - $week = explode('|', $weeks); - $w1 = $w2 = $w3 = $w4 = $w5 = $w6 = $w7 = false; - foreach($week as $w){ - switch($w){ - case 1: $w1 = true; break; - case 2: $w2 = true; break; - case 3: $w3 = true; break; - case 4: $w4 = true; break; - case 5: $w5 = true; break; - case 6: $w6 = true; break; - case 7: $w7 = true; break; - } - } - $data['W1'] = $w1; - $data['W2'] = $w2; - $data['W3'] = $w3; - $data['W4'] = $w4; - $data['W5'] = $w5; - $data['W6'] = $w6; - $data['W7'] = $w7; - - $years = $data['SCH_MONTHS']; - $year = explode('|',$years); - $m1 = $m2 = $m3 = $m4 = $m5 = $m6 = $m7 = $m8 = $m9 = $m10 = $m11 = $m12 = false; - foreach ($year as $month){ - switch($month){ - case 1: $m1 = true; break; - case 2: $m2 = true; break; - case 3: $m3 = true; break; - case 4: $m4 = true; break; - case 5: $m5 = true; break; - case 6: $m6 = true; break; - case 7: $m7 = true; break; - case 8: $m8 = true; break; - case 9: $m9 = true; break; - case 10: $m10 = true; break; - case 11: $m11 = true; break; - case 12: $m12 = true; break; - } - } - - $data['M1'] = $m1; - $data['M2'] = $m2; - $data['M3'] = $m3; - $data['M4'] = $m4; - $data['M5'] = $m5; - $data['M6'] = $m6; - $data['M7'] = $m7; - $data['M8'] = $m8; - $data['M9'] = $m9; - $data['M10'] = $m10; - $data['M11'] = $m11; - $data['M12'] = $m12; - - $start_options = $data['SCH_START_DAY']; - $options = explode('|', $start_options); - $data['TYPE_CMB'] = $options[0]; - if ($options[0]==1){ - $data['EACH_DAY'] = $options[1]; - }else{ - $data['CMB_1'] = $options[1]; - $data['CMB_2'] = $options[2]; - } - $this->success = true; - $this->data = $data; - } + $years = $data['SCH_MONTHS']; + $year = explode( '|', $years ); + $m1 = $m2 = $m3 = $m4 = $m5 = $m6 = $m7 = $m8 = $m9 = $m10 = $m11 = $m12 = false; + foreach ($year as $month) { + switch ($month) { + case 1: + $m1 = true; + break; + case 2: + $m2 = true; + break; + case 3: + $m3 = true; + break; + case 4: + $m4 = true; + break; + case 5: + $m5 = true; + break; + case 6: + $m6 = true; + break; + case 7: + $m7 = true; + break; + case 8: + $m8 = true; + break; + case 9: + $m9 = true; + break; + case 10: + $m10 = true; + break; + case 11: + $m11 = true; + break; + case 12: + $m12 = true; + break; + } + } + + $data['M1'] = $m1; + $data['M2'] = $m2; + $data['M3'] = $m3; + $data['M4'] = $m4; + $data['M5'] = $m5; + $data['M6'] = $m6; + $data['M7'] = $m7; + $data['M8'] = $m8; + $data['M9'] = $m9; + $data['M10'] = $m10; + $data['M11'] = $m11; + $data['M12'] = $m12; + + $start_options = $data['SCH_START_DAY']; + $options = explode( '|', $start_options ); + $data['TYPE_CMB'] = $options[0]; + if ($options[0] == 1) { + $data['EACH_DAY'] = $options[1]; + } else { + $data['CMB_1'] = $options[1]; + $data['CMB_2'] = $options[2]; + } + $this->success = true; + $this->data = $data; + } + +} //End caseSchedulerProxy -} //End caseSchedulerProxy \ No newline at end of file diff --git a/workflow/engine/controllers/dashboard.php b/workflow/engine/controllers/dashboard.php index 6c2ed5f7c..ad5b312cd 100644 --- a/workflow/engine/controllers/dashboard.php +++ b/workflow/engine/controllers/dashboard.php @@ -1,322 +1,337 @@ pmDashlet = new PMDashlet(); - } - - // Functions for the dashboards users module - Start - - public function index($httpData) { - try { - $this->setJSVar('dashletsInstances', $this->getDashletsInstancesForCurrentUser()); - $this->includeExtJS('dashboard/index'); - $this->includeExtJSLib('ux/portal'); - G::RenderPage('publish', 'extJs'); + // Class constructor + public function __construct () + { + G::LoadClass( 'pmDashlet' ); + $this->pmDashlet = new PMDashlet(); } - catch (Exception $error) { - //ToDo: Display a error message - } - } - public function renderDashletInstance($data) { - try { - if (!isset($data->DAS_INS_UID)) { - $data->DAS_INS_UID = ''; - } - if ($data->DAS_INS_UID == '') { - throw new Exception('Parameter "DAS_INS_UID" is empty.'); - } - $this->pmDashlet->setup($data->DAS_INS_UID); + // Functions for the dashboards users module - Start - if (!isset($_REQUEST['w']) ) { - $width = 300; - } - else { - $width = $_REQUEST['w']; - } - $this->pmDashlet->render($width); - } - catch (Exception $error) { - //ToDo: Show the error message - echo $error->getMessage(); - } - } - private function getDashletsInstancesForCurrentUser() { - try { - if (!isset($_SESSION['USER_LOGGED'])) { - throw new Exception('The session has expired.'); - } - return $this->pmDashlet->getDashletsInstancesForUser($_SESSION['USER_LOGGED']); + public function index ($httpData) + { + try { + $this->setJSVar( 'dashletsInstances', $this->getDashletsInstancesForCurrentUser() ); + $this->includeExtJS( 'dashboard/index' ); + $this->includeExtJSLib( 'ux/portal' ); + G::RenderPage( 'publish', 'extJs' ); + } catch (Exception $error) { + //ToDo: Display a error message + } } - catch (Exception $error) { - throw $error; + + public function renderDashletInstance ($data) + { + try { + if (! isset( $data->DAS_INS_UID )) { + $data->DAS_INS_UID = ''; + } + if ($data->DAS_INS_UID == '') { + throw new Exception( 'Parameter "DAS_INS_UID" is empty.' ); + } + $this->pmDashlet->setup( $data->DAS_INS_UID ); + + if (! isset( $_REQUEST['w'] )) { + $width = 300; + } else { + $width = $_REQUEST['w']; + } + $this->pmDashlet->render( $width ); + } catch (Exception $error) { + //ToDo: Show the error message + echo $error->getMessage(); + } } - } - // Functions for the dashboards users module - End - - // Functions for the dasboards administration module - Start - - public function dashletsList() { - try { - $this->includeExtJS('dashboard/dashletsList'); - if (isset($_SESSION['__DASHBOARD_ERROR__'])) { - $this->setJSVar('__DASHBOARD_ERROR__', $_SESSION['__DASHBOARD_ERROR__']); - unset($_SESSION['__DASHBOARD_ERROR__']); - } - $this->setView('dashboard/dashletsList'); - G::RenderPage('publish', 'extJs'); + private function getDashletsInstancesForCurrentUser () + { + try { + if (! isset( $_SESSION['USER_LOGGED'] )) { + throw new Exception( 'The session has expired.' ); + } + return $this->pmDashlet->getDashletsInstancesForUser( $_SESSION['USER_LOGGED'] ); + } catch (Exception $error) { + throw $error; + } } - catch (Exception $error) { - //ToDo: Display a error message - } - } - public function getDashletsInstances($data) { - $this->setResponseType('json'); - $result = new stdclass(); - $result->status = 'OK'; - try { - if (!isset($data->start)) { - $data->start = null; - } - if (!isset($data->limit)) { - $data->limit = null; - } - $result->dashletsInstances = $this->pmDashlet->getDashletsInstances($data->start, $data->limit); - $result->totalDashletsInstances = $this->pmDashlet->getDashletsInstancesQuantity(); - } - catch (Exception $error) { - $result->status = 'ERROR'; - $result->message = $error->getMessage(); - } - return $result; - } + // Functions for the dashboards users module - End - public function dashletInstanceForm($data) { - try { - $this->includeExtJS('dashboard/dashletInstanceForm', false); - $this->setView('dashboard/dashletInstanceForm'); - if (!isset($data->DAS_INS_UID)) { - $data->DAS_INS_UID = ''; - } - $dashlets = $this->getDashlets(); - $this->setJSVar('storeDasUID', $dashlets); - if ($data->DAS_INS_UID != '') { - $this->pmDashlet->setup($data->DAS_INS_UID); - $this->setJSVar('dashletInstance', $this->pmDashlet->getDashletInstance()); - $this->setJSVar('additionalFields', PMDashlet::getAdditionalFields(get_class($this->pmDashlet->getDashletObject()))); - } - else { - $dashletInstance = new stdclass(); - $dashletInstance->DAS_UID = $dashlets[0][0]; - $dashlet = new Dashlet(); - $dashletFields = $dashlet->load($dashletInstance->DAS_UID); - $this->setJSVar('dashletInstance', $dashletInstance); - $this->setJSVar('additionalFields', PMDashlet::getAdditionalFields($dashletFields['DAS_CLASS'])); - } - G::RenderPage('publish', 'extJs'); - return null; + + // Functions for the dasboards administration module - Start + + + public function dashletsList () + { + try { + $this->includeExtJS( 'dashboard/dashletsList' ); + if (isset( $_SESSION['__DASHBOARD_ERROR__'] )) { + $this->setJSVar( '__DASHBOARD_ERROR__', $_SESSION['__DASHBOARD_ERROR__'] ); + unset( $_SESSION['__DASHBOARD_ERROR__'] ); + } + $this->setView( 'dashboard/dashletsList' ); + G::RenderPage( 'publish', 'extJs' ); + } catch (Exception $error) { + //ToDo: Display a error message + } } - catch (Exception $error) { - $_SESSION['__DASHBOARD_ERROR__'] = $error->getMessage(); - G::header('Location: dashletsList'); - die(); + + public function getDashletsInstances ($data) + { + $this->setResponseType( 'json' ); + $result = new stdclass(); + $result->status = 'OK'; + try { + if (! isset( $data->start )) { + $data->start = null; + } + if (! isset( $data->limit )) { + $data->limit = null; + } + $result->dashletsInstances = $this->pmDashlet->getDashletsInstances( $data->start, $data->limit ); + $result->totalDashletsInstances = $this->pmDashlet->getDashletsInstancesQuantity(); + } catch (Exception $error) { + $result->status = 'ERROR'; + $result->message = $error->getMessage(); + } + return $result; } - } - public function saveDashletInstance($data) { - $this->setResponseType('json'); - $result = new stdclass(); - $result->status = 'OK'; - try { - $this->pmDashlet->saveDashletInstance(get_object_vars($data)); + public function dashletInstanceForm ($data) + { + try { + $this->includeExtJS( 'dashboard/dashletInstanceForm', false ); + $this->setView( 'dashboard/dashletInstanceForm' ); + if (! isset( $data->DAS_INS_UID )) { + $data->DAS_INS_UID = ''; + } + $dashlets = $this->getDashlets(); + $this->setJSVar( 'storeDasUID', $dashlets ); + if ($data->DAS_INS_UID != '') { + $this->pmDashlet->setup( $data->DAS_INS_UID ); + $this->setJSVar( 'dashletInstance', $this->pmDashlet->getDashletInstance() ); + $this->setJSVar( 'additionalFields', PMDashlet::getAdditionalFields( get_class( $this->pmDashlet->getDashletObject() ) ) ); + } else { + $dashletInstance = new stdclass(); + $dashletInstance->DAS_UID = $dashlets[0][0]; + $dashlet = new Dashlet(); + $dashletFields = $dashlet->load( $dashletInstance->DAS_UID ); + $this->setJSVar( 'dashletInstance', $dashletInstance ); + $this->setJSVar( 'additionalFields', PMDashlet::getAdditionalFields( $dashletFields['DAS_CLASS'] ) ); + } + G::RenderPage( 'publish', 'extJs' ); + return null; + } catch (Exception $error) { + $_SESSION['__DASHBOARD_ERROR__'] = $error->getMessage(); + G::header( 'Location: dashletsList' ); + die(); + } } - catch (Exception $error) { - $result->status = 'ERROR'; - $result->message = $error->getMessage(); + + public function saveDashletInstance ($data) + { + $this->setResponseType( 'json' ); + $result = new stdclass(); + $result->status = 'OK'; + try { + $this->pmDashlet->saveDashletInstance( get_object_vars( $data ) ); + } catch (Exception $error) { + $result->status = 'ERROR'; + $result->message = $error->getMessage(); + } + return $result; } - return $result; - } - public function deleteDashletInstance($data) { - $this->setResponseType('json'); - $result = new stdclass(); - $result->status = 'OK'; - try { - if (!isset($data->DAS_INS_UID)) { - $data->DAS_INS_UID = ''; - } - if ($data->DAS_INS_UID == '') { - throw new Exception('Parameter "DAS_INS_UID" is empty.'); - } - $this->pmDashlet->deleteDashletInstance($data->DAS_INS_UID); + public function deleteDashletInstance ($data) + { + $this->setResponseType( 'json' ); + $result = new stdclass(); + $result->status = 'OK'; + try { + if (! isset( $data->DAS_INS_UID )) { + $data->DAS_INS_UID = ''; + } + if ($data->DAS_INS_UID == '') { + throw new Exception( 'Parameter "DAS_INS_UID" is empty.' ); + } + $this->pmDashlet->deleteDashletInstance( $data->DAS_INS_UID ); + } catch (Exception $error) { + $result->status = 'ERROR'; + $result->message = $error->getMessage(); + } + return $result; } - catch (Exception $error) { - $result->status = 'ERROR'; - $result->message = $error->getMessage(); + + public function getAdditionalFields ($data) + { + $this->setResponseType( 'json' ); + $result = new stdclass(); + $result->status = 'OK'; + try { + $dashlet = new Dashlet(); + $dashletFields = $dashlet->load( $data->DAS_UID ); + if (! is_null( $dashletFields )) { + $result->additionalFields = PMDashlet::getAdditionalFields( $dashletFields['DAS_CLASS'] ); + } else { + throw new Exception( 'Dashlet "' . $data->DAS_UID . '" does not exist.' ); + } + } catch (Exception $error) { + $result->status = 'ERROR'; + $result->message = $error->getMessage(); + } + return $result; } - return $result; - } - public function getAdditionalFields($data) { - $this->setResponseType('json'); - $result = new stdclass(); - $result->status = 'OK'; - try { - $dashlet = new Dashlet(); - $dashletFields = $dashlet->load($data->DAS_UID); - if (!is_null($dashletFields)) { - $result->additionalFields = PMDashlet::getAdditionalFields($dashletFields['DAS_CLASS']); - } - else { - throw new Exception('Dashlet "' . $data->DAS_UID . '" does not exist.'); - } + public function getOwnersByType ($data) + { + $this->setResponseType( 'json' ); + $result = new stdclass(); + $result->status = 'OK'; + try { + switch ($data->type) { + case 'EVERYBODY': + $result->total = 0; + $result->owners = array (); + break; + case 'USER': + require_once 'classes/model/Users.php'; + + $users = array (); + + $usersInstance = new Users(); + $allUsers = $usersInstance->getAll(); + foreach ($allUsers->data as $user) { + $users[] = array ('OWNER_UID' => $user['USR_UID'],'OWNER_NAME' => $user['USR_FIRSTNAME'] . ' ' . $user['USR_LASTNAME'] + ); + } + + $result->total = $allUsers->totalCount; + $result->owners = $users; + break; + case 'DEPARTMENT': + require_once 'classes/model/Department.php'; + require_once 'classes/model/Content.php'; + + $departments = array (); + //SELECT + $criteria = new Criteria( 'workflow' ); + $criteria->setDistinct(); + $criteria->addSelectColumn( DepartmentPeer::DEP_UID ); + $criteria->addSelectColumn( ContentPeer::CON_VALUE ); + //FROM + $conditions = array (); + $conditions[] = array (DepartmentPeer::DEP_UID,ContentPeer::CON_ID + ); + $conditions[] = array (ContentPeer::CON_CATEGORY,DBAdapter::getStringDelimiter() . 'DEPO_TITLE' . DBAdapter::getStringDelimiter() + ); + $conditions[] = array (ContentPeer::CON_LANG,DBAdapter::getStringDelimiter() . 'en' . DBAdapter::getStringDelimiter() + ); + $criteria->addJoinMC( $conditions, Criteria::LEFT_JOIN ); + //WHERE + $criteria->add( DepartmentPeer::DEP_STATUS, 'ACTIVE' ); + //ORDER BY + $criteria->addAscendingOrderByColumn( ContentPeer::CON_VALUE ); + + $dataset = DepartmentPeer::doSelectRS( $criteria ); + $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $dataset->next(); + while ($row = $dataset->getRow()) { + $departments[] = array ('OWNER_UID' => $row['DEP_UID'],'OWNER_NAME' => $row['CON_VALUE'] + ); + $dataset->next(); + } + + $result->total = DepartmentPeer::doCount( $criteria ); + $result->owners = $departments; + break; + case 'GROUP': + require_once 'classes/model/Groupwf.php'; + require_once 'classes/model/Content.php'; + + $groups = array (); + //SELECT + $criteria = new Criteria( 'workflow' ); + $criteria->setDistinct(); + $criteria->addSelectColumn( GroupwfPeer::GRP_UID ); + $criteria->addSelectColumn( ContentPeer::CON_VALUE ); + //FROM + $conditions = array (); + $conditions[] = array (GroupwfPeer::GRP_UID,ContentPeer::CON_ID + ); + $conditions[] = array (ContentPeer::CON_CATEGORY,DBAdapter::getStringDelimiter() . 'GRP_TITLE' . DBAdapter::getStringDelimiter() + ); + $conditions[] = array (ContentPeer::CON_LANG,DBAdapter::getStringDelimiter() . 'en' . DBAdapter::getStringDelimiter() + ); + $criteria->addJoinMC( $conditions, Criteria::LEFT_JOIN ); + //WHERE + $criteria->add( GroupwfPeer::GRP_STATUS, 'ACTIVE' ); + //ORDER BY + $criteria->addAscendingOrderByColumn( ContentPeer::CON_VALUE ); + + $dataset = GroupwfPeer::doSelectRS( $criteria ); + $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $dataset->next(); + while ($row = $dataset->getRow()) { + $groups[] = array ('OWNER_UID' => $row['GRP_UID'],'OWNER_NAME' => $row['CON_VALUE'] + ); + $dataset->next(); + } + + $result->total = GroupwfPeer::doCount( $criteria ); + $result->owners = $groups; + break; + } + } catch (Exception $error) { + $result->status = 'ERROR'; + $result->message = $error->getMessage(); + } + return $result; } - catch (Exception $error) { - $result->status = 'ERROR'; - $result->message = $error->getMessage(); - } - return $result; - } - public function getOwnersByType($data) { - $this->setResponseType('json'); - $result = new stdclass(); - $result->status = 'OK'; - try { - switch ($data->type) { - case 'EVERYBODY': - $result->total = 0; - $result->owners = array(); - break; - case 'USER': - require_once 'classes/model/Users.php'; + private function getDashlets () + { + try { + require_once 'classes/model/Dashlet.php'; - $users = array(); + $dashlets = array (); - $usersInstance = new Users(); - $allUsers = $usersInstance->getAll(); - foreach ($allUsers->data as $user) { - $users[] = array('OWNER_UID' => $user['USR_UID'], 'OWNER_NAME' => $user['USR_FIRSTNAME'] . ' ' . $user['USR_LASTNAME']); - } + //SELECT + $criteria = new Criteria( 'workflow' ); + $criteria->addSelectColumn( DashletPeer::DAS_UID ); + $criteria->addSelectColumn( DashletPeer::DAS_TITLE ); + //ORDER BY + $criteria->addAscendingOrderByColumn( DashletPeer::DAS_TITLE ); - $result->total = $allUsers->totalCount; - $result->owners = $users; - break; - case 'DEPARTMENT': - require_once 'classes/model/Department.php'; - require_once 'classes/model/Content.php'; - - $departments = array(); - //SELECT - $criteria = new Criteria('workflow'); - $criteria->setDistinct(); - $criteria->addSelectColumn(DepartmentPeer::DEP_UID); - $criteria->addSelectColumn(ContentPeer::CON_VALUE); - //FROM - $conditions = array(); - $conditions[] = array(DepartmentPeer::DEP_UID, ContentPeer::CON_ID); - $conditions[] = array(ContentPeer::CON_CATEGORY, DBAdapter::getStringDelimiter() . 'DEPO_TITLE' . DBAdapter::getStringDelimiter()); - $conditions[] = array(ContentPeer::CON_LANG, DBAdapter::getStringDelimiter() . 'en' . DBAdapter::getStringDelimiter()); - $criteria->addJoinMC($conditions, Criteria::LEFT_JOIN); - //WHERE - $criteria->add(DepartmentPeer::DEP_STATUS, 'ACTIVE'); - //ORDER BY - $criteria->addAscendingOrderByColumn(ContentPeer::CON_VALUE); - - $dataset = DepartmentPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $dataset->next(); - while ($row = $dataset->getRow()) { - $departments[] = array('OWNER_UID' => $row['DEP_UID'], 'OWNER_NAME' => $row['CON_VALUE']); + $dataset = DashletPeer::doSelectRS( $criteria ); + $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $dataset->next(); - } + while ($row = $dataset->getRow()) { + $dashlets[] = array ($row['DAS_UID'],$row['DAS_TITLE'] + ); + $dataset->next(); + } - $result->total = DepartmentPeer::doCount($criteria); - $result->owners = $departments; - break; - case 'GROUP': - require_once 'classes/model/Groupwf.php'; - require_once 'classes/model/Content.php'; - - $groups = array(); - //SELECT - $criteria = new Criteria('workflow'); - $criteria->setDistinct(); - $criteria->addSelectColumn(GroupwfPeer::GRP_UID); - $criteria->addSelectColumn(ContentPeer::CON_VALUE); - //FROM - $conditions = array(); - $conditions[] = array(GroupwfPeer::GRP_UID, ContentPeer::CON_ID); - $conditions[] = array(ContentPeer::CON_CATEGORY, DBAdapter::getStringDelimiter() . 'GRP_TITLE' . DBAdapter::getStringDelimiter()); - $conditions[] = array(ContentPeer::CON_LANG, DBAdapter::getStringDelimiter() . 'en' . DBAdapter::getStringDelimiter()); - $criteria->addJoinMC($conditions, Criteria::LEFT_JOIN); - //WHERE - $criteria->add(GroupwfPeer::GRP_STATUS, 'ACTIVE'); - //ORDER BY - $criteria->addAscendingOrderByColumn(ContentPeer::CON_VALUE); - - $dataset = GroupwfPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $dataset->next(); - while ($row = $dataset->getRow()) { - $groups[] = array('OWNER_UID' => $row['GRP_UID'], 'OWNER_NAME' => $row['CON_VALUE']); - $dataset->next(); - } - - $result->total = GroupwfPeer::doCount($criteria); - $result->owners = $groups; - break; - } + } catch (Exception $error) { + throw $error; + } + return $dashlets; } - catch (Exception $error) { - $result->status = 'ERROR'; - $result->message = $error->getMessage(); - } - return $result; - } - private function getDashlets() { - try { - require_once 'classes/model/Dashlet.php'; + // Functions for the dasboards administration module - End +} - $dashlets = array(); - - //SELECT - $criteria = new Criteria('workflow'); - $criteria->addSelectColumn(DashletPeer::DAS_UID); - $criteria->addSelectColumn(DashletPeer::DAS_TITLE); - //ORDER BY - $criteria->addAscendingOrderByColumn(DashletPeer::DAS_TITLE); - - $dataset = DashletPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $dataset->next(); - while ($row = $dataset->getRow()) { - $dashlets[] = array($row['DAS_UID'], $row['DAS_TITLE']); - $dataset->next(); - } - - } - catch (Exception $error) { - throw $error; - } - return $dashlets; - } - - // Functions for the dasboards administration module - End -} \ No newline at end of file diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index 4fd7d5051..57bdd58e5 100755 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -1,4 +1,5 @@ clientBrowser = G::getBrowser(); + public function __construct () + { + //die($_SESSION['user_experience']); + // setting client browser information + $this->clientBrowser = G::getBrowser(); - // getting the ux type from user o group conf. - $this->userUxType = isset($_SESSION['user_experience'])? $_SESSION['user_experience']: 'SIMPLIFIED'; - $this->lastSkin = isset($_SESSION['user_last_skin']) ? $_SESSION['user_last_skin'] : 'classic'; - $this->userUxBaseTemplate = (is_dir(PATH_CUSTOM_SKINS . 'uxs')) ? PATH_CUSTOM_SKINS . 'simplified' . PATH_SEP . 'templates' : 'home'; + // getting the ux type from user o group conf. + $this->userUxType = isset( $_SESSION['user_experience'] ) ? $_SESSION['user_experience'] : 'SIMPLIFIED'; + $this->lastSkin = isset( $_SESSION['user_last_skin'] ) ? $_SESSION['user_last_skin'] : 'classic'; + $this->userUxBaseTemplate = (is_dir( PATH_CUSTOM_SKINS . 'uxs' )) ? PATH_CUSTOM_SKINS . 'simplified' . PATH_SEP . 'templates' : 'home'; - if (isset($_SESSION['USER_LOGGED']) && !empty($_SESSION['USER_LOGGED'])) { - $this->userID = isset($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : null; - $this->userName = isset($_SESSION['USR_USERNAME']) ? $_SESSION['USR_USERNAME'] : ''; - $this->userFullName = isset($_SESSION['USR_FULLNAME']) ? $_SESSION['USR_FULLNAME'] : ''; - $this->userRolName = isset($_SESSION['USR_ROLENAME']) ? $_SESSION['USR_ROLENAME'] : ''; - } - } - - public function login($httpData) - { - //start new session - @session_destroy (); - session_start (); - session_regenerate_id (); - - $data = isset($httpData->d) ? unserialize(base64_decode($httpData->d)) : ''; - $template = $this->clientBrowser['name'] == 'msie' ? 'login_ie' : 'login_standard'; - $skin = $this->clientBrowser['name'] == 'msie' ? $this->lastSkin : 'simplified'; - - if (!is_array($data)) { - $data = array('u'=>'', 'p'=>'', 'm'=>''); - } - - $this->setVar('msg', $data['m']); - $this->setVar('usr', $data['u']); - $this->setVar('pwd', $data['p']); - $this->setVar('skin', $skin); - - $this->setView($this->userUxBaseTemplate . PATH_SEP . $template); - $this->render(); - } - - /** - * getting default list - * @param string $httpData (opional) - */ - - public function index($httpData) - { - if ($this->userUxType == 'SINGLE') { - $this->indexSingle($httpData); - return; - } - - require_once 'classes/model/UsersProperties.php'; - G::LoadClass('process'); - G::LoadClass('case'); - - $userProperty = new UsersProperties(); - $process = new Process(); - $case = new Cases(); - G::loadClass('system'); - $sysConf = System::getSystemConfiguration(PATH_CONFIG . 'env.ini'); - - //Get ProcessStatistics Info - $start = 0; - $limit = ''; - - $proData = $process->getAllProcesses($start, $limit); - $processList = $case->getStartCasesPerType($_SESSION['USER_LOGGED'], 'category'); - $switchLink = $userProperty->getUserLocation($_SESSION['USER_LOGGED']); - - if (substr($sysConf['default_skin'], 0, 2) == 'ux') { - $_SESSION['_defaultUserLocation'] = $switchLink; - $switchLink = '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . $sysConf['default_skin'] . '/main'; - } - - unset($processList[0]); - - //Get simplified options - global $G_TMP_MENU; - - $mnu = new Menu(); - $mnu->load('simplified'); - $arrayMnuOption = array(); - $mnuNewCase = array(); - - if (!empty($mnu->Options)) { - foreach ($mnu->Options as $index => $value) { - $option = array( - 'id' => $mnu->Id[$index], - 'url' => $mnu->Options[$index], - 'label' => $mnu->Labels[$index], - 'icon' => $mnu->Icons[$index], - 'class' => $mnu->ElementClass[$index] - ); - - if ($mnu->Id[$index] != 'S_NEW_CASE') { - $arrayMnuOption[] = $option; + if (isset( $_SESSION['USER_LOGGED'] ) && ! empty( $_SESSION['USER_LOGGED'] )) { + $this->userID = isset( $_SESSION['USER_LOGGED'] ) ? $_SESSION['USER_LOGGED'] : null; + $this->userName = isset( $_SESSION['USR_USERNAME'] ) ? $_SESSION['USR_USERNAME'] : ''; + $this->userFullName = isset( $_SESSION['USR_FULLNAME'] ) ? $_SESSION['USR_FULLNAME'] : ''; + $this->userRolName = isset( $_SESSION['USR_ROLENAME'] ) ? $_SESSION['USR_ROLENAME'] : ''; } - else { - $mnuNewCase = $option; + } + + public function login ($httpData) + { + //start new session + @session_destroy(); + session_start(); + session_regenerate_id(); + + $data = isset( $httpData->d ) ? unserialize( base64_decode( $httpData->d ) ) : ''; + $template = $this->clientBrowser['name'] == 'msie' ? 'login_ie' : 'login_standard'; + $skin = $this->clientBrowser['name'] == 'msie' ? $this->lastSkin : 'simplified'; + + if (! is_array( $data )) { + $data = array ('u' => '','p' => '','m' => '' + ); } - } + + $this->setVar( 'msg', $data['m'] ); + $this->setVar( 'usr', $data['u'] ); + $this->setVar( 'pwd', $data['p'] ); + $this->setVar( 'skin', $skin ); + + $this->setView( $this->userUxBaseTemplate . PATH_SEP . $template ); + $this->render(); } - $this->setView($this->userUxBaseTemplate . PATH_SEP . 'index'); + /** + * getting default list + * + * @param string $httpData (opional) + */ - $this->setVar('usrUid', $this->userID); - $this->setVar('userName', $this->userName); - $this->setVar('processList', $processList); - $this->setVar('canStartCase', $case->canStartCase($_SESSION ['USER_LOGGED'])); - $this->setVar('userUxType', $this->userUxType); - $this->setVar('clientBrowser', $this->clientBrowser['name']); - $this->setVar('switchLink', $switchLink); - $this->setVar('arrayMnuOption', $arrayMnuOption); - $this->setVar('mnuNewCase', $mnuNewCase); + public function index ($httpData) + { + if ($this->userUxType == 'SINGLE') { + $this->indexSingle( $httpData ); + return; + } - $this->render(); - } + require_once 'classes/model/UsersProperties.php'; + G::LoadClass( 'process' ); + G::LoadClass( 'case' ); - public function indexSingle($httpData) - { - require_once 'classes/model/Step.php'; - G::LoadClass('applications'); + $userProperty = new UsersProperties(); + $process = new Process(); + $case = new Cases(); + G::loadClass( 'system' ); + $sysConf = System::getSystemConfiguration( PATH_CONFIG . 'env.ini' ); - $apps = new Applications(); - $step = new Step; + //Get ProcessStatistics Info + $start = 0; + $limit = ''; - $cases = $apps->getAll($this->userID, 0, 1, 'todo'); + $proData = $process->getAllProcesses( $start, $limit ); + $processList = $case->getStartCasesPerType( $_SESSION['USER_LOGGED'], 'category' ); + $switchLink = $userProperty->getUserLocation( $_SESSION['USER_LOGGED'] ); - if (!isset($cases['data'][0])) { - //the current user has not any aplication to do - $this->setView($this->userUxBaseTemplate . PATH_SEP .'indexSingle'); - $this->setVar('default_url', $this->userUxBaseTemplate . "/" . 'error?no=2'); - $this->render(); - exit(); + if (substr( $sysConf['default_skin'], 0, 2 ) == 'ux') { + $_SESSION['_defaultUserLocation'] = $switchLink; + $switchLink = '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . $sysConf['default_skin'] . '/main'; + } + + unset( $processList[0] ); + + //Get simplified options + global $G_TMP_MENU; + + $mnu = new Menu(); + $mnu->load( 'simplified' ); + $arrayMnuOption = array (); + $mnuNewCase = array (); + + if (! empty( $mnu->Options )) { + foreach ($mnu->Options as $index => $value) { + $option = array ('id' => $mnu->Id[$index],'url' => $mnu->Options[$index],'label' => $mnu->Labels[$index],'icon' => $mnu->Icons[$index],'class' => $mnu->ElementClass[$index] + ); + + if ($mnu->Id[$index] != 'S_NEW_CASE') { + $arrayMnuOption[] = $option; + } else { + $mnuNewCase = $option; + } + } + } + + $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'index' ); + + $this->setVar( 'usrUid', $this->userID ); + $this->setVar( 'userName', $this->userName ); + $this->setVar( 'processList', $processList ); + $this->setVar( 'canStartCase', $case->canStartCase( $_SESSION['USER_LOGGED'] ) ); + $this->setVar( 'userUxType', $this->userUxType ); + $this->setVar( 'clientBrowser', $this->clientBrowser['name'] ); + $this->setVar( 'switchLink', $switchLink ); + $this->setVar( 'arrayMnuOption', $arrayMnuOption ); + $this->setVar( 'mnuNewCase', $mnuNewCase ); + + $this->render(); } - $lastApp = $cases['data'][0]; - $_SESSION['INDEX'] = $lastApp['DEL_INDEX']; - $_SESSION['APPLICATION'] = $lastApp['APP_UID']; - $_SESSION['PROCESS'] = $lastApp['PRO_UID']; - $_SESSION['TASK'] = $lastApp['TAS_UID']; + public function indexSingle ($httpData) + { + require_once 'classes/model/Step.php'; + G::LoadClass( 'applications' ); - $steps = $apps->getSteps($lastApp['APP_UID'], $lastApp['DEL_INDEX'], $lastApp['TAS_UID'], $lastApp['PRO_UID']); - $lastStep = array_pop($steps); - $lastStep['title'] = G::LoadTranslation('ID_FINISH'); - $steps[] = $lastStep; + $apps = new Applications(); + $step = new Step(); - $this->setView($this->userUxBaseTemplate . PATH_SEP . 'indexSingle'); + $cases = $apps->getAll( $this->userID, 0, 1, 'todo' ); - $this->setVar('usrUid', $this->userID); - $this->setVar('userName', $this->userName); - $this->setVar('steps', $steps); - $this->setVar('default_url', "cases/cases_Open?APP_UID={$lastApp['APP_UID']}&DEL_INDEX={$lastApp['DEL_INDEX']}&action=todo"); + if (! isset( $cases['data'][0] )) { + //the current user has not any aplication to do + $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'indexSingle' ); + $this->setVar( 'default_url', $this->userUxBaseTemplate . "/" . 'error?no=2' ); + $this->render(); + exit(); + } - $this->render(); - } + $lastApp = $cases['data'][0]; + $_SESSION['INDEX'] = $lastApp['DEL_INDEX']; + $_SESSION['APPLICATION'] = $lastApp['APP_UID']; + $_SESSION['PROCESS'] = $lastApp['PRO_UID']; + $_SESSION['TASK'] = $lastApp['TAS_UID']; - public function appList($httpData) + $steps = $apps->getSteps( $lastApp['APP_UID'], $lastApp['DEL_INDEX'], $lastApp['TAS_UID'], $lastApp['PRO_UID'] ); + $lastStep = array_pop( $steps ); + $lastStep['title'] = G::LoadTranslation( 'ID_FINISH' ); + $steps[] = $lastStep; + + $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'indexSingle' ); + + $this->setVar( 'usrUid', $this->userID ); + $this->setVar( 'userName', $this->userName ); + $this->setVar( 'steps', $steps ); + $this->setVar( 'default_url', "cases/cases_Open?APP_UID={$lastApp['APP_UID']}&DEL_INDEX={$lastApp['DEL_INDEX']}&action=todo" ); + + $this->render(); + } + + public function appList ($httpData) { // setting default list applications types [default: todo] - $httpData->t = isset($httpData->t)? $httpData->t : 'todo'; + $httpData->t = isset( $httpData->t ) ? $httpData->t : 'todo'; // setting main list title switch ($httpData->t) { @@ -200,116 +197,120 @@ class Home extends Controller $title = 'Unassigned Inbox'; break; default: - $title = ucwords($httpData->t); - break; + $title = ucwords( $httpData->t ); + break; } // getting apps data - $cases = $this->getAppsData($httpData->t); + $cases = $this->getAppsData( $httpData->t ); // settings html template - $this->setView($this->userUxBaseTemplate . PATH_SEP . 'appList'); + $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'appList' ); // settings vars and rendering - $this->setVar('cases', $cases['data']); - $this->setVar('cases_count', $cases['totalCount']); - $this->setVar('title', $title); - $this->setVar('appListStart', $this->appListLimit); - $this->setVar('appListLimit', 10); - $this->setVar('listType', $httpData->t); + $this->setVar( 'cases', $cases['data'] ); + $this->setVar( 'cases_count', $cases['totalCount'] ); + $this->setVar( 'title', $title ); + $this->setVar( 'appListStart', $this->appListLimit ); + $this->setVar( 'appListLimit', 10 ); + $this->setVar( 'listType', $httpData->t ); $this->render(); } - public function getApps($httpData) - { - $cases = $this->getAppsData($httpData->t, $httpData->start, $httpData->limit); - - $this->setView($this->userUxBaseTemplate . PATH_SEP . 'applications'); - $this->setVar('cases', $cases['data']); - $this->render(); - } - - public function getAppsData($type, $start=null, $limit=null) + public function getApps ($httpData) { - require_once ( "classes/model/AppNotes.php" ); - G::LoadClass('applications'); + $cases = $this->getAppsData( $httpData->t, $httpData->start, $httpData->limit ); + + $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'applications' ); + $this->setVar( 'cases', $cases['data'] ); + $this->render(); + } + + public function getAppsData ($type, $start = null, $limit = null) + { + require_once ("classes/model/AppNotes.php"); + G::LoadClass( 'applications' ); $apps = new Applications(); $appNotes = new AppNotes(); - $start = empty($start) ? $this->appListStart : $start; - $limit = empty($limit) ? $this->appListLimit : $limit; + $start = empty( $start ) ? $this->appListStart : $start; + $limit = empty( $limit ) ? $this->appListLimit : $limit; $notesStart = 0; $notesLimit = 4; - $cases = $apps->getAll($this->userID, $start, $limit, $type); + $cases = $apps->getAll( $this->userID, $start, $limit, $type ); //g::pr($cases['data']); die; + // formating & complitting apps data with 'Notes' foreach ($cases['data'] as $i => $row) { // Formatting - $appTitle = str_replace('#', '', $row['APP_TITLE']); + $appTitle = str_replace( '#', '', $row['APP_TITLE'] ); - if (is_numeric($appTitle)) { - $cases['data'][$i]['APP_TITLE'] = G::LoadTranslation('ID_CASE'). ' ' . $appTitle; + if (is_numeric( $appTitle )) { + $cases['data'][$i]['APP_TITLE'] = G::LoadTranslation( 'ID_CASE' ) . ' ' . $appTitle; } - if (isset($row['DEL_DELEGATE_DATE'])) { - $cases['data'][$i]['DEL_DELEGATE_DATE'] = G::getformatedDate($row['DEL_DELEGATE_DATE'], - 'M d, yyyy - h:i:s'); + if (isset( $row['DEL_DELEGATE_DATE'] )) { + $cases['data'][$i]['DEL_DELEGATE_DATE'] = G::getformatedDate( $row['DEL_DELEGATE_DATE'], 'M d, yyyy - h:i:s' ); } - if (isset($row['APP_DEL_PREVIOUS_USER'])) { - $cases['data'][$i]['APP_DEL_PREVIOUS_USER'] = ucwords($row['APP_DEL_PREVIOUS_USER']); + if (isset( $row['APP_DEL_PREVIOUS_USER'] )) { + $cases['data'][$i]['APP_DEL_PREVIOUS_USER'] = ucwords( $row['APP_DEL_PREVIOUS_USER'] ); } // Completting with Notes - $notes = $appNotes->getNotesList($row['APP_UID'], '', $notesStart, $notesLimit); + $notes = $appNotes->getNotesList( $row['APP_UID'], '', $notesStart, $notesLimit ); $notes = $notes['array']; $cases['data'][$i]['NOTES_COUNT'] = $notes['totalCount']; - $cases['data'][$i]['NOTES_LIST'] = $notes['notes']; + $cases['data'][$i]['NOTES_LIST'] = $notes['notes']; } return $cases; } - public function startCase($httpData) - { - G::LoadClass('case'); - $case = new Cases(); - $aData = $case->startCase($httpData->id, $_SESSION['USER_LOGGED']); + public function startCase ($httpData) + { + G::LoadClass( 'case' ); + $case = new Cases(); + $aData = $case->startCase( $httpData->id, $_SESSION['USER_LOGGED'] ); - $_SESSION['APPLICATION'] = $aData['APPLICATION']; - $_SESSION['INDEX'] = $aData['INDEX']; - $_SESSION['PROCESS'] = $aData['PROCESS']; - $_SESSION['TASK'] = $httpData->id; - $_SESSION['STEP_POSITION'] = 0; - $_SESSION['CASES_REFRESH'] = true; + $_SESSION['APPLICATION'] = $aData['APPLICATION']; + $_SESSION['INDEX'] = $aData['INDEX']; + $_SESSION['PROCESS'] = $aData['PROCESS']; + $_SESSION['TASK'] = $httpData->id; + $_SESSION['STEP_POSITION'] = 0; + $_SESSION['CASES_REFRESH'] = true; - // Execute Events - require_once 'classes/model/Event.php'; - $event = new Event(); - $event->createAppEvents($_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['TASK']); + // Execute Events + require_once 'classes/model/Event.php'; + $event = new Event(); + $event->createAppEvents( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['TASK'] ); - $oCase = new Cases(); - $aNextStep = $oCase->getNextStep($_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION']); - //../cases/cases_Open?APP_UID={$APP.APP_UID}&DEL_INDEX={$APP.DEL_INDEX}&action=todo - $aNextStep['PAGE'] = '../cases/cases_Open?APP_UID='.$aData['APPLICATION'].'&DEL_INDEX='.$aData['INDEX'].'&action=draft'; - $_SESSION ['BREAKSTEP'] ['NEXT_STEP'] = $aNextStep; + $oCase = new Cases(); + $aNextStep = $oCase->getNextStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] ); + //../cases/cases_Open?APP_UID={$APP.APP_UID}&DEL_INDEX={$APP.DEL_INDEX}&action=todo + $aNextStep['PAGE'] = '../cases/cases_Open?APP_UID=' . $aData['APPLICATION'] . '&DEL_INDEX=' . $aData['INDEX'] . '&action=draft'; + $_SESSION['BREAKSTEP']['NEXT_STEP'] = $aNextStep; - $this->redirect($aNextStep['PAGE']); - } - - public function error($httpData) - { - $httpData->no = isset($httpData->no) ? $httpData->no : 0; - - switch ($httpData->no) { - case 2: $tpl = $this->userUxBaseTemplate . PATH_SEP . 'noAppsMsg'; break; - default: $tpl = $this->userUxBaseTemplate . PATH_SEP . 'error'; + $this->redirect( $aNextStep['PAGE'] ); } - $this->setView($tpl); - $this->render(); - } + public function error ($httpData) + { + $httpData->no = isset( $httpData->no ) ? $httpData->no : 0; + + switch ($httpData->no) { + case 2: + $tpl = $this->userUxBaseTemplate . PATH_SEP . 'noAppsMsg'; + break; + default: + $tpl = $this->userUxBaseTemplate . PATH_SEP . 'error'; + } + + $this->setView( $tpl ); + $this->render(); + } } + diff --git a/workflow/engine/controllers/installer.php b/workflow/engine/controllers/installer.php index e6068a8ef..f94a92415 100644 --- a/workflow/engine/controllers/installer.php +++ b/workflow/engine/controllers/installer.php @@ -1,4 +1,5 @@ path_config = PATH_CORE.'config/'; - $this->path_languages = PATH_CORE.'content/languages/'; - $this->path_plugins = PATH_CORE.'plugins/'; - $this->path_xmlforms = PATH_CORE.'xmlform/'; - $this->path_public = PATH_HOME.'public_html/index.html'; - $this->path_shared = PATH_TRUNK.'shared/'; - $this->path_sep = PATH_SEP; - } - public function index($httpData) - { - $step1_txt = 'If any of these items is not supported (marked as No) then please take actions to correct them.

' . - 'Failure to do so could lead to your ProcessMaker installation not functioning correctly!

' . - //'(*) MSSQL Support is optional.

' . - '(*) OpenSSL is optional.

' . - '(*) LDAP is optional.'; - - $step2_txt = 'These settings are recommended for PHP in order to ensure full compatibility with ProcessMaker. <> ' . - 'However, ProcessMaker still operate if your settings do not quite match the recommended'; - $step3_txt = 'In order for ProcessMaker to work correctly, it needs to be able read and write to certain directories and their files.
' . - 'Make sure to give read and write access to the directories listed below and all their subdirectories and files.'; - $step4_txt = 'ProcessMaker stores all of its data in a database. Enter the address and port number used by the database. Also enter' . - 'the username and password of the database user who will set up the databases used by ProcessMaker
'; - $step5_txt = 'ProcessMaker uses workspaces to store data in the database. Please enter a valid workspace name and a username and password to login'. - ' as the administrator.'; - $step6_txt = 'xxx'; - - $licenseContent = file_get_contents(PATH_TRUNK . 'LICENSE.txt'); - - $this->includeExtJS('installer/CardLayout', false); - $this->includeExtJS('installer/Wizard', false); - $this->includeExtJS('installer/Header', false); - $this->includeExtJS('installer/Card', false); - - $this->includeExtJS('installer/installer_cards'); - $this->includeExtJS('installer/main', false); - - $this->setJSVar('licenseTxt', $licenseContent); - $this->setJSVar('step1_txt', $step1_txt); - $this->setJSVar('step2_txt', $step2_txt); - $this->setJSVar('step3_txt', $step3_txt); - $this->setJSVar('step4_txt', $step4_txt); - $this->setJSVar('step5_txt', $step5_txt); - $this->setJSVar('step6_txt', $step6_txt); - - $this->setJSVar('path_config', $this->path_config ); - $this->setJSVar('path_languages', $this->path_languages ); - $this->setJSVar('path_plugins', $this->path_plugins ); - $this->setJSVar('path_xmlforms', $this->path_xmlforms ); - $this->setJSVar('path_public', $this->path_public ); - $this->setJSVar('path_shared', $this->path_shared ); - $this->setJSVar('path_sep', $this->path_sep ); - - $this->setView('installer/main'); - - G::RenderPage('publish', 'extJs'); - } - - public function newSite() - { - $textStep1 = 'ProcessMaker stores all of its data in a database. This screen gives the installation program the information needed to create this database.

' . - 'If you are installing ProcessMaker on a remote web server, you will need to get this information from your Database Server.'; - $textStep2 = 'ProcessMaker uses a workspaces to store data. Please select a valid workspace name and credentials to log in it.'; - - $this->includeExtJS('installer/CardLayout', false); - $this->includeExtJS('installer/Wizard', false); - $this->includeExtJS('installer/Header', false); - $this->includeExtJS('installer/Card', false); - $this->includeExtJS('installer/newSite', false); - - $this->setJSVar('textStep1', $textStep1); - $this->setJSVar('textStep2', $textStep2); - - $this->setJSVar('DB_ADAPTER', DB_ADAPTER); - $aux = explode(':', DB_HOST); - $this->setJSVar('DB_HOST', $aux[0]); - $this->setJSVar('DB_PORT', isset($aux[1]) ? $aux[1] : (DB_ADAPTER == 'mssql' ? '1433' : '3306')); - $this->setJSVar('DB_NAME', 'workflow'); - $this->setJSVar('DB_USER', ''); - $this->setJSVar('DB_PASS', ''); - $this->setJSVar('pathConfig', PATH_CORE . 'config' . PATH_SEP); - $this->setJSVar('pathLanguages', PATH_LANGUAGECONT); - $this->setJSVar('pathPlugins', PATH_PLUGINS); - $this->setJSVar('pathXmlforms', PATH_XMLFORM); - $this->setJSVar('pathShared', PATH_DATA); - - $this->setView('installer/newSite'); - - G::RenderPage('publish', 'extJs'); - } - - public function getSystemInfo() - { - $this->setResponseType('json'); - - // PHP info and verification - $phpVer = phpversion(); - preg_match('/[0-9\.]+/', $phpVer, $match); - $phpVerNum = (float) $match[0]; - - $info = new stdclass(); - $info->php = new stdclass(); - $info->mysql = new stdclass(); - $info->mssql = new stdclass(); - $info->openssl = new stdclass(); - $info->curl = new stdclass(); - $info->dom = new stdclass(); - $info->gd = new stdclass(); - $info->multibyte = new stdclass(); - $info->soap = new stdclass(); - $info->ldap = new stdclass(); - $info->memory = new stdclass(); - - $info->php->version = phpversion(); - $info->php->result = $phpVerNum >= 5.1 ? true : false; - - // MYSQL info and verification - $info->mysql->result = false; - if ( function_exists ( 'mysql_query' ) ) { - $mysqlVer = mysql_get_client_info(); - preg_match('/[0-9\.]+/', $mysqlVer, $match); - $mysqlNum = (float) $match[0]; - $info->mysql->version = 'Client API version ' . $mysqlVer; - $info->mysql->result = $mysqlNum >= 5.0 ? true : false; + public function __construct () + { + $this->path_config = PATH_CORE . 'config/'; + $this->path_languages = PATH_CORE . 'content/languages/'; + $this->path_plugins = PATH_CORE . 'plugins/'; + $this->path_xmlforms = PATH_CORE . 'xmlform/'; + $this->path_public = PATH_HOME . 'public_html/index.html'; + $this->path_shared = PATH_TRUNK . 'shared/'; + $this->path_sep = PATH_SEP; } - // MSSQL info and verification - $info->mssql->result = false; - $info->mssql->version = 'not enabled'; - if ( function_exists ( 'mssql_query' ) ) { - $info->mssql->result = true; - $info->mssql->version = 'enabled'; + public function index ($httpData) + { + $step1_txt = 'If any of these items is not supported (marked as No) then please take actions to correct them.

' . 'Failure to do so could lead to your ProcessMaker installation not functioning correctly!

' . + //'(*) MSSQL Support is optional.

' . + '(*) OpenSSL is optional.

' . '(*) LDAP is optional.'; + + $step2_txt = 'These settings are recommended for PHP in order to ensure full compatibility with ProcessMaker. <> ' . 'However, ProcessMaker still operate if your settings do not quite match the recommended'; + $step3_txt = 'In order for ProcessMaker to work correctly, it needs to be able read and write to certain directories and their files.
' . 'Make sure to give read and write access to the directories listed below and all their subdirectories and files.'; + $step4_txt = 'ProcessMaker stores all of its data in a database. Enter the address and port number used by the database. Also enter' . 'the username and password of the database user who will set up the databases used by ProcessMaker
'; + $step5_txt = 'ProcessMaker uses workspaces to store data in the database. Please enter a valid workspace name and a username and password to login' . ' as the administrator.'; + $step6_txt = 'xxx'; + + $licenseContent = file_get_contents( PATH_TRUNK . 'LICENSE.txt' ); + + $this->includeExtJS( 'installer/CardLayout', false ); + $this->includeExtJS( 'installer/Wizard', false ); + $this->includeExtJS( 'installer/Header', false ); + $this->includeExtJS( 'installer/Card', false ); + + $this->includeExtJS( 'installer/installer_cards' ); + $this->includeExtJS( 'installer/main', false ); + + $this->setJSVar( 'licenseTxt', $licenseContent ); + $this->setJSVar( 'step1_txt', $step1_txt ); + $this->setJSVar( 'step2_txt', $step2_txt ); + $this->setJSVar( 'step3_txt', $step3_txt ); + $this->setJSVar( 'step4_txt', $step4_txt ); + $this->setJSVar( 'step5_txt', $step5_txt ); + $this->setJSVar( 'step6_txt', $step6_txt ); + + $this->setJSVar( 'path_config', $this->path_config ); + $this->setJSVar( 'path_languages', $this->path_languages ); + $this->setJSVar( 'path_plugins', $this->path_plugins ); + $this->setJSVar( 'path_xmlforms', $this->path_xmlforms ); + $this->setJSVar( 'path_public', $this->path_public ); + $this->setJSVar( 'path_shared', $this->path_shared ); + $this->setJSVar( 'path_sep', $this->path_sep ); + + $this->setView( 'installer/main' ); + + G::RenderPage( 'publish', 'extJs' ); } - // OpenSSL info - $info->openssl->result = false; - $info->openssl->version = 'not enabled'; - if ( function_exists ( 'openssl_open' ) ) { - $info->openssl->result = true; - $info->openssl->version = 'enabled'; + public function newSite () + { + $textStep1 = 'ProcessMaker stores all of its data in a database. This screen gives the installation program the information needed to create this database.

' . 'If you are installing ProcessMaker on a remote web server, you will need to get this information from your Database Server.'; + $textStep2 = 'ProcessMaker uses a workspaces to store data. Please select a valid workspace name and credentials to log in it.'; + + $this->includeExtJS( 'installer/CardLayout', false ); + $this->includeExtJS( 'installer/Wizard', false ); + $this->includeExtJS( 'installer/Header', false ); + $this->includeExtJS( 'installer/Card', false ); + $this->includeExtJS( 'installer/newSite', false ); + + $this->setJSVar( 'textStep1', $textStep1 ); + $this->setJSVar( 'textStep2', $textStep2 ); + + $this->setJSVar( 'DB_ADAPTER', DB_ADAPTER ); + $aux = explode( ':', DB_HOST ); + $this->setJSVar( 'DB_HOST', $aux[0] ); + $this->setJSVar( 'DB_PORT', isset( $aux[1] ) ? $aux[1] : (DB_ADAPTER == 'mssql' ? '1433' : '3306') ); + $this->setJSVar( 'DB_NAME', 'workflow' ); + $this->setJSVar( 'DB_USER', '' ); + $this->setJSVar( 'DB_PASS', '' ); + $this->setJSVar( 'pathConfig', PATH_CORE . 'config' . PATH_SEP ); + $this->setJSVar( 'pathLanguages', PATH_LANGUAGECONT ); + $this->setJSVar( 'pathPlugins', PATH_PLUGINS ); + $this->setJSVar( 'pathXmlforms', PATH_XMLFORM ); + $this->setJSVar( 'pathShared', PATH_DATA ); + + $this->setView( 'installer/newSite' ); + + G::RenderPage( 'publish', 'extJs' ); } - // Curl info - $info->curl->result = false; - $info->curl->version = 'not enabled'; - if ( function_exists ( 'curl_version' ) ) { - $info->curl->result = true; - $version = curl_version(); - $info->curl->version = 'cURL ' . $version['version']; - $info->openssl->version = $version['ssl_version']; - } + public function getSystemInfo () + { + $this->setResponseType( 'json' ); - // DOMDocument info - $info->dom->result = false; - $info->dom->version = 'not enabled'; - if ( class_exists ( 'DOMDocument' ) ) { - $info->dom->result = true; - $info->dom->version = 'enabled'; - } + // PHP info and verification + $phpVer = phpversion(); + preg_match( '/[0-9\.]+/', $phpVer, $match ); + $phpVerNum = (float) $match[0]; - // GD info - $info->gd->result = false; - $info->gd->version = 'not enabled'; - if ( function_exists ( 'gd_info' ) ) { - $info->gd->result = true; - $gdinfo = gd_info(); - $info->gd->version = $gdinfo['GD Version'] ; - } + $info = new stdclass(); + $info->php = new stdclass(); + $info->mysql = new stdclass(); + $info->mssql = new stdclass(); + $info->openssl = new stdclass(); + $info->curl = new stdclass(); + $info->dom = new stdclass(); + $info->gd = new stdclass(); + $info->multibyte = new stdclass(); + $info->soap = new stdclass(); + $info->ldap = new stdclass(); + $info->memory = new stdclass(); - // Multibyte info - $info->multibyte->result = false; - $info->multibyte->version = 'not enabled'; - if ( function_exists ( 'mb_check_encoding' ) ) { - $info->multibyte->result = true; - $info->multibyte->version = 'enabled'; - } + $info->php->version = phpversion(); + $info->php->result = $phpVerNum >= 5.1 ? true : false; - // soap info - $info->soap->result = false; - $info->soap->version = 'not enabled'; - if ( class_exists ( 'SoapClient' ) ) { - $info->soap->result = true; - $info->soap->version = 'enabled'; - } - - // ldap info - $info->ldap->result = false; - $info->ldap->version = 'not enabled'; - if ( function_exists ( 'ldap_connect' ) ) { - $info->ldap->result = true; - $info->ldap->version = 'enabled'; - } - - // memory limit verification - $memory = (int)ini_get("memory_limit"); - $info->memory->version = $memory . 'M'; - if ( $memory > 80 ) { - $info->memory->result = true; - } - else { - $info->memory->result = false; - } - - return $info; - } - - public function is_dir_writable($path) - { - return G::is_writable_r($path); - } - - public function getPermissionInfo() - { - $this->setResponseType('json'); - - $info = new StdClass(); - $info->success = true; - $noWritableFiles = array(); - - // pathConfig - $info->pathConfig->message = 'unwriteable'; - $info->pathConfig->result = G::is_writable_r($_REQUEST['pathConfig'], $noWritableFiles); - if ( $info->pathConfig->result ) { - $info->pathConfig->message = 'writeable'; - } - else { - $info->success = false; - } - - $info->pathLanguages->message = 'unwriteable'; - $info->pathLanguages->result = G::is_writable_r($_REQUEST['pathLanguages'], $noWritableFiles); - if ( $info->pathLanguages->result ) { - $info->pathLanguages->message = 'writeable'; - } - else { - $info->success = false; - } - - $info->pathPlugins->message = 'unwriteable'; - $info->pathPlugins->result = G::is_writable_r($_REQUEST['pathPlugins'], $noWritableFiles); - if ( $info->pathPlugins->result ) { - $info->pathPlugins->message = 'writeable'; - } - else { - $info->success = false; - } - - $info->pathXmlforms->message = 'unwriteable'; - $info->pathXmlforms->result = G::is_writable_r($_REQUEST['pathXmlforms'], $noWritableFiles); - if ( $info->pathXmlforms->result ) { - $info->pathXmlforms->message = 'writeable'; - } - else { - $info->success = false; - } - - $info->pathPublic->message = 'unwriteable'; - $info->pathPublic->result = G::is_writable_r($_REQUEST['pathPublic'], $noWritableFiles); - if ( $info->pathPublic->result ) { - $info->pathShared->message = 'writeable'; - } - else { - $info->success = false; - } - - $info->pathShared->message = 'unwriteable'; - $info->pathShared->result = G::is_writable_r($_REQUEST['pathShared'], $noWritableFiles); - if ( $info->pathShared->result ) { - $info->pathShared->message = 'writeable'; - } - else { - G::verifyPath($_REQUEST['pathShared'], true); - $info->pathShared->result = G::is_writable_r($_REQUEST['pathShared'], $noWritableFiles); - if ( $info->pathShared->result ) - $info->pathShared->message = 'writeable'; - else - $info->success = false; - } - - if ($info->pathShared->result) { - $aux = pathinfo($_REQUEST['pathLogFile']); - G::verifyPath($aux['dirname'], true); - if (is_dir($aux['dirname'])) { - if (!file_exists($_REQUEST['pathLogFile'])) { - @file_put_contents($_REQUEST['pathLogFile'], ''); + // MYSQL info and verification + $info->mysql->result = false; + if (function_exists( 'mysql_query' )) { + $mysqlVer = mysql_get_client_info(); + preg_match( '/[0-9\.]+/', $mysqlVer, $match ); + $mysqlNum = (float) $match[0]; + $info->mysql->version = 'Client API version ' . $mysqlVer; + $info->mysql->result = $mysqlNum >= 5.0 ? true : false; } - } + + // MSSQL info and verification + $info->mssql->result = false; + $info->mssql->version = 'not enabled'; + if (function_exists( 'mssql_query' )) { + $info->mssql->result = true; + $info->mssql->version = 'enabled'; + } + + // OpenSSL info + $info->openssl->result = false; + $info->openssl->version = 'not enabled'; + if (function_exists( 'openssl_open' )) { + $info->openssl->result = true; + $info->openssl->version = 'enabled'; + } + + // Curl info + $info->curl->result = false; + $info->curl->version = 'not enabled'; + if (function_exists( 'curl_version' )) { + $info->curl->result = true; + $version = curl_version(); + $info->curl->version = 'cURL ' . $version['version']; + $info->openssl->version = $version['ssl_version']; + } + + // DOMDocument info + $info->dom->result = false; + $info->dom->version = 'not enabled'; + if (class_exists( 'DOMDocument' )) { + $info->dom->result = true; + $info->dom->version = 'enabled'; + } + + // GD info + $info->gd->result = false; + $info->gd->version = 'not enabled'; + if (function_exists( 'gd_info' )) { + $info->gd->result = true; + $gdinfo = gd_info(); + $info->gd->version = $gdinfo['GD Version']; + } + + // Multibyte info + $info->multibyte->result = false; + $info->multibyte->version = 'not enabled'; + if (function_exists( 'mb_check_encoding' )) { + $info->multibyte->result = true; + $info->multibyte->version = 'enabled'; + } + + // soap info + $info->soap->result = false; + $info->soap->version = 'not enabled'; + if (class_exists( 'SoapClient' )) { + $info->soap->result = true; + $info->soap->version = 'enabled'; + } + + // ldap info + $info->ldap->result = false; + $info->ldap->version = 'not enabled'; + if (function_exists( 'ldap_connect' )) { + $info->ldap->result = true; + $info->ldap->version = 'enabled'; + } + + // memory limit verification + $memory = (int) ini_get( "memory_limit" ); + $info->memory->version = $memory . 'M'; + if ($memory > 80) { + $info->memory->result = true; + } else { + $info->memory->result = false; + } + + return $info; } - $info->pathLogFile->message = 'Could not create the installation log'; - $info->pathLogFile->result = file_exists($_REQUEST['pathLogFile']); - - if ($info->pathLogFile->result) { - $info->pathLogFile->message = 'Installation log created'; + public function is_dir_writable ($path) + { + return G::is_writable_r( $path ); } - if ($info->success) { - $info->notify = 'Success, all required directories are writable.'; - } - else { - $info->notify = 'Some directories and/or files inside it are not writable.'; + public function getPermissionInfo () + { + $this->setResponseType( 'json' ); + + $info = new StdClass(); + $info->success = true; + $noWritableFiles = array (); + + // pathConfig + $info->pathConfig->message = 'unwriteable'; + $info->pathConfig->result = G::is_writable_r( $_REQUEST['pathConfig'], $noWritableFiles ); + if ($info->pathConfig->result) { + $info->pathConfig->message = 'writeable'; + } else { + $info->success = false; + } + + $info->pathLanguages->message = 'unwriteable'; + $info->pathLanguages->result = G::is_writable_r( $_REQUEST['pathLanguages'], $noWritableFiles ); + if ($info->pathLanguages->result) { + $info->pathLanguages->message = 'writeable'; + } else { + $info->success = false; + } + + $info->pathPlugins->message = 'unwriteable'; + $info->pathPlugins->result = G::is_writable_r( $_REQUEST['pathPlugins'], $noWritableFiles ); + if ($info->pathPlugins->result) { + $info->pathPlugins->message = 'writeable'; + } else { + $info->success = false; + } + + $info->pathXmlforms->message = 'unwriteable'; + $info->pathXmlforms->result = G::is_writable_r( $_REQUEST['pathXmlforms'], $noWritableFiles ); + if ($info->pathXmlforms->result) { + $info->pathXmlforms->message = 'writeable'; + } else { + $info->success = false; + } + + $info->pathPublic->message = 'unwriteable'; + $info->pathPublic->result = G::is_writable_r( $_REQUEST['pathPublic'], $noWritableFiles ); + if ($info->pathPublic->result) { + $info->pathShared->message = 'writeable'; + } else { + $info->success = false; + } + + $info->pathShared->message = 'unwriteable'; + $info->pathShared->result = G::is_writable_r( $_REQUEST['pathShared'], $noWritableFiles ); + if ($info->pathShared->result) { + $info->pathShared->message = 'writeable'; + } else { + G::verifyPath( $_REQUEST['pathShared'], true ); + $info->pathShared->result = G::is_writable_r( $_REQUEST['pathShared'], $noWritableFiles ); + if ($info->pathShared->result) { + $info->pathShared->message = 'writeable'; + } else { + $info->success = false; + } + } + + if ($info->pathShared->result) { + $aux = pathinfo( $_REQUEST['pathLogFile'] ); + G::verifyPath( $aux['dirname'], true ); + if (is_dir( $aux['dirname'] )) { + if (! file_exists( $_REQUEST['pathLogFile'] )) { + @file_put_contents( $_REQUEST['pathLogFile'], '' ); + } + } + } + + $info->pathLogFile->message = 'Could not create the installation log'; + $info->pathLogFile->result = file_exists( $_REQUEST['pathLogFile'] ); + + if ($info->pathLogFile->result) { + $info->pathLogFile->message = 'Installation log created'; + } + + if ($info->success) { + $info->notify = 'Success, all required directories are writable.'; + } else { + $info->notify = 'Some directories and/or files inside it are not writable.'; + } + + $info->noWritableFiles = $noWritableFiles; + + return $info; } - $info->noWritableFiles = $noWritableFiles; - - return $info; - } - - public function testConnection () - { - $this->setResponseType('json'); - if ($_REQUEST['db_engine'] == 'mysql') { - return $this->testMySQLconnection(); - } - else { - return $this->testMSSQLconnection(); - } - } - - /** - * log the queries and other information to install.log, - * the install.log files should be placed in shared/logs - * for that reason we are using the $_REQUEST of pathShared - */ - public function installLog( $text ) - { - $serverAddr = $_SERVER['SERVER_ADDR']; - //if this function is called outside the createWorkspace, just returns and do nothing - if ( !isset( $_REQUEST['pathShared']) ) - return; - - //log file is in shared/logs - $pathShared = trim($_REQUEST['pathShared']); - if ( substr($pathShared,-1) != '/' ) $pathShared .= '/'; - $logFile = $pathShared . 'log/install.log'; - - if ( !is_file($logFile) ) { - G::mk_dir(dirname($pathShared)); - $fpt = fopen ( $logFile, 'w' ); - if ( $fpt !== NULL ) { - fwrite( $fpt, sprintf ( "%s %s\n", date('Y:m:d H:i:s'), '----- starting log file ------' )); - fclose( $fpt); - } - else { - throw ( new Exception ( sprintf ( "File '%s' is not writeable. Please check permission before continue", $logFile ) ) ); - return $false; - } + public function testConnection () + { + $this->setResponseType( 'json' ); + if ($_REQUEST['db_engine'] == 'mysql') { + return $this->testMySQLconnection(); + } else { + return $this->testMSSQLconnection(); + } } - $fpt = fopen ( $logFile, 'a' ); - fwrite( $fpt, sprintf ( "%s %s\n", date('Y:m:d H:i:s'), trim($text) )); - fclose( $fpt); - return true; - } + /** + * log the queries and other information to install.log, + * the install.log files should be placed in shared/logs + * for that reason we are using the $_REQUEST of pathShared + */ + public function installLog ($text) + { + $serverAddr = $_SERVER['SERVER_ADDR']; + //if this function is called outside the createWorkspace, just returns and do nothing + if (! isset( $_REQUEST['pathShared'] )) { + return; + } + //log file is in shared/logs + $pathShared = trim( $_REQUEST['pathShared'] ); + if (substr( $pathShared, - 1 ) != '/') { + $pathShared .= '/'; + } + $logFile = $pathShared . 'log/install.log'; - /** - * function to create a workspace - * in fact this function is calling appropiate functions for mysql and mssql - */ - public function createWorkspace() - { - $this->setResponseType('json'); - if ($_REQUEST['db_engine'] == 'mysql') { - $info = $this->createMySQLWorkspace(); - } - else { - $info = $this->createMSSQLWorkspace(); + if (! is_file( $logFile )) { + G::mk_dir( dirname( $pathShared ) ); + $fpt = fopen( $logFile, 'w' ); + if ($fpt !== null) { + fwrite( $fpt, sprintf( "%s %s\n", date( 'Y:m:d H:i:s' ), '----- starting log file ------' ) ); + fclose( $fpt ); + } else { + throw (new Exception( sprintf( "File '%s' is not writeable. Please check permission before continue", $logFile ) )); + return $false; + } + } + + $fpt = fopen( $logFile, 'a' ); + fwrite( $fpt, sprintf( "%s %s\n", date( 'Y:m:d H:i:s' ), trim( $text ) ) ); + fclose( $fpt ); + return true; } - return $info; - } + /** + * function to create a workspace + * in fact this function is calling appropiate functions for mysql and mssql + */ + public function createWorkspace () + { + $this->setResponseType( 'json' ); + if ($_REQUEST['db_engine'] == 'mysql') { + $info = $this->createMySQLWorkspace(); + } else { + $info = $this->createMSSQLWorkspace(); + } - public function forceTogenerateTranslationsFiles($url) - { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, (isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS'] != '' ? 'https://' : 'http://') : 'http://') . $_SERVER['HTTP_HOST'] . '/js/ext/translation.en.js?r=' . rand(1, 10000)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 60); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); - curl_exec($ch); - curl_close($ch); - } - - /** - * send a query to MySQL and log the query - */ - public function mysqlQuery($sql) - { - $this->installLog($sql); - $query = @mysql_query($sql, $this->link); - if (!$query) { - $errorMessage = mysql_error($this->link); - $this->installLog('MySQL error: ' . $errorMessage); - throw new Exception($errorMessage); - return false; - } - @mysql_free_result($query); - return true; - } - - /** - * send a query to MSSQL and log the query - */ - public function mssqlQuery($sql) - { - $this->installLog( $sql ); - $query = @mssql_query($sql, $this->link); - if (!$query) { - $errorMessage = mssql_get_last_message(); - $this->installLog ( 'MSSQL error: ' . $errorMessage ); - throw ( new Exception ( $errorMessage ) ); - return false; - } - @mssql_free_result($query); - return true; - } - - /** - * query_sql_file send many statements to server - * - * @param string $file - * @param string $connection - * @return array $report - */ - public function mysqlFileQuery($file) - { - if ( !is_file($file) ) { - throw ( new Exception ( sprintf ( "File $file is not a valid sql file", $file ) ) ); - return $false; - } - $this->installLog ( 'Procesing: ' . $file ); - $startTime = microtime(true); - // $content = file_get_contents($file); - // $queries = explode(';', $content); - - // foreach( $queries as $sql) { - // if (trim($sql) != '') { - // $query = @mysql_query($sql, $this->link); - // if (!$query) { - // $errorMessage = mysql_error($this->link); - - // $this->installLog ( sprintf ( 'MySQL error: %s Query: %s ', $errorMessage, $sql ) ); - // throw ( new Exception ( $errorMessage ) ); - // return false; - // } - // } - // } - - //erik: New Update, to support more complex queries - - $lines = file($file); - $previous = NULL; - $errors = ''; - @mysql_query("SET NAMES 'utf8';"); - foreach ($lines as $j => $line) { - $line = trim($line); // Remove comments from the script - - if (strpos($line, "--") === 0) { - $line = substr($line, 0, strpos($line, "--")); - } - - if (empty($line)) { - continue; - } - - if (strpos($line, "#") === 0) { - $line = substr($line, 0, strpos($line, "#")); - } - - if (empty($line)) { - continue; - } - - // Concatenate the previous line, if any, with the current - if ($previous) { - $line = $previous . " " . $line; - } - $previous = NULL; - - // If the current line doesnt end with ; then put this line together - // with the next one, thus supporting multi-line statements. - if (strrpos($line, ";") != strlen($line) - 1) { - $previous = $line; - continue; - } - - $line = substr($line, 0, strrpos($line, ";")); - @mysql_query($line, $this->link); + return $info; } - $endTime = microtime(true); - $this->installLog ( sprintf ('File: %s processed in %3.2f seconds', basename($file) , $endTime - $startTime ) ); - return true; - } - - /** - * query_sql_file send many statements to server - * - * @param string $file - * @param string $connection - * @return array $report - */ - public function mssqlFileQuery($file) - { - if ( !is_file($file) ) { - throw ( new Exception ( sprintf ( "File $file is not a valid sql file", $file ) ) ); - return $false; + public function forceTogenerateTranslationsFiles ($url) + { + $ch = curl_init(); + curl_setopt( $ch, CURLOPT_URL, (isset( $_SERVER['HTTPS'] ) ? ($_SERVER['HTTPS'] != '' ? 'https://' : 'http://') : 'http://') . $_SERVER['HTTP_HOST'] . '/js/ext/translation.en.js?r=' . rand( 1, 10000 ) ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); + curl_setopt( $ch, CURLOPT_FRESH_CONNECT, 1 ); + curl_setopt( $ch, CURLOPT_TIMEOUT, 60 ); + curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 20 ); + curl_exec( $ch ); + curl_close( $ch ); } - $this->installLog ( 'Procesing: ' . $file ); - $startTime = microtime(true); - $content = file_get_contents($file); - $queries = explode(';', $content); - foreach( $queries as $sql) { - $query = @mssql_query($sql, $this->link); - if (!$query) { - $errorMessage = mssql_get_last_message(); - - $this->installLog ( sprintf ( 'MSSQL error: %s Query: %s ', $errorMessage, $sql ) ); - throw ( new Exception ( $errorMessage ) ); - return false; - } + /** + * send a query to MySQL and log the query + */ + public function mysqlQuery ($sql) + { + $this->installLog( $sql ); + $query = @mysql_query( $sql, $this->link ); + if (! $query) { + $errorMessage = mysql_error( $this->link ); + $this->installLog( 'MySQL error: ' . $errorMessage ); + throw new Exception( $errorMessage ); + return false; + } + @mysql_free_result( $query ); + return true; } - $endTime = microtime(true); - $this->installLog ( sprintf ('File: %s processed in %3.2f seconds', basename($file) , $endTime - $startTime ) ); - return true; - } - /** - * set Grant Privileges for MySQL - * - * @param string $psUser - * @param string $psPassword - * @param string $psDatabase - * @return void - */ - public function setGrantPrivilegesMySQL($psUser, $psPassword, $psDatabase, $host) - { - $host = ($host == 'localhost' || $host == '127.0.0.1' ? 'localhost' : '%'); - $query = sprintf("GRANT ALL PRIVILEGES ON `%s`.* TO %s@'%s' IDENTIFIED BY '%s' WITH GRANT OPTION", $psDatabase, $psUser, $host, $psPassword); - $this->mysqlQuery($query); - } + /** + * send a query to MSSQL and log the query + */ + public function mssqlQuery ($sql) + { + $this->installLog( $sql ); + $query = @mssql_query( $sql, $this->link ); + if (! $query) { + $errorMessage = mssql_get_last_message(); + $this->installLog( 'MSSQL error: ' . $errorMessage ); + throw (new Exception( $errorMessage )); + return false; + } + @mssql_free_result( $query ); + return true; + } - /** - * set Grant Privileges for SQLServer - * - * @param string $psUser - * @param string $psPassword - * @param string $psDatabase - * @return void - */ - public function setGrantPrivilegesMSSQL($psUser, $psPassword, $psDatabase) - { - - $query = sprintf ( "IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'%s') DROP LOGIN [%s]", $psUser, $psUser ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "CREATE LOGIN [%s] WITH PASSWORD=N'%s', DEFAULT_DATABASE=[%s], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF ", $psUser, $psPassword, $psDatabase ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "USE %s;", $psDatabase ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'%s') DROP USER [%s]", $psUser, $psUser ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "CREATE USER %s FOR LOGIN %s;", $psUser, $psUser ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "sp_addrolemember 'db_owner', '%s' ", $psUser ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "sp_addrolemember 'db_ddladmin', '%s' ", $psUser ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "sp_addrolemember 'db_accessadmin', '%s' ", $psUser ); - $this->mssqlQuery( $query ); - - $query = sprintf ( "use master " ); - $this->mssqlQuery( $query ); - - return true; - } - - public function createMySQLWorkspace() - { - ini_set('max_execution_time', '0'); - $info->result = false; - $info->message = ''; - $info->canRedirect = true; - - $db_hostname = trim($_REQUEST['db_hostname']); - $db_port = trim($_REQUEST['db_port']); - $db_username = trim($_REQUEST['db_username']); - $db_password = trim($_REQUEST['db_password']); - $wf = trim($_REQUEST['wfDatabase']); - $rb = trim($_REQUEST['rbDatabase']); - $rp = trim($_REQUEST['rpDatabase']); - $workspace = trim($_REQUEST['workspace']); - $pathConfig = trim($_REQUEST['pathConfig']); - $pathLanguages = trim($_REQUEST['pathLanguages']); - $pathPlugins = trim($_REQUEST['pathPlugins']); - $pathShared = trim($_REQUEST['pathShared']); - $pathXmlforms = trim($_REQUEST['pathXmlforms']); - $adminPassword = trim($_REQUEST['adminPassword']); - $adminUsername = trim($_REQUEST['adminUsername']); - $deleteDB = ($_REQUEST['deleteDB'] == 'true'); - - if ( substr($pathShared,-1) != '/' ) $pathShared .= '/'; - - $this->installLog ( '-------------------------------------------' ); - $this->installLog ( sprintf ( "Creating workspace '%s' ", $workspace) ); - - try { - $db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname ; - $this->link = @mysql_connect($db_host, $db_username, $db_password); - $this->installLog (sprintf ( "Connected to server %s:%d using user: '%s' ", $db_hostname, $db_port, $db_username ) ); - - if ($deleteDB) { - $q = sprintf('DROP DATABASE IF EXISTS %s;' , $wf, $wf); - $this->mysqlQuery($q); - - $q = sprintf('DROP DATABASE IF EXISTS %s;' , $rb, $rb); - $this->mysqlQuery($q); - - $q = sprintf('DROP DATABASE IF EXISTS %s;' , $rp, $rp); - $this->mysqlQuery($q); - } - - // CREATE databases wf_workflow, rb_workflow and rp_workflow - $q = sprintf('CREATE DATABASE IF NOT EXISTS %s;' , $wf, $wf); - $this->mysqlQuery($q); - - $q = sprintf('CREATE DATABASE IF NOT EXISTS %s;' , $rb, $rb); - $this->mysqlQuery($q); - - $q = sprintf('CREATE DATABASE IF NOT EXISTS %s;' , $rp, $rp); - $this->mysqlQuery($q); - - // CREATE users and GRANT Privileges - $wfPass = G::generate_password(12); - $rbPass = G::generate_password(12); - $rpPass = G::generate_password(12); - $this->setGrantPrivilegesMySQL($wf, $wfPass, $wf, $db_hostname); - $this->setGrantPrivilegesMySQL($rb, $rbPass, $rb, $db_hostname); - $this->setGrantPrivilegesMySQL($rp, $rpPass, $rp, $db_hostname); - - // Generate the db.php file and folders - $path_site = $pathShared . "/sites/" . $workspace ."/"; - $db_file = $path_site. "db.php"; - @mkdir($path_site, 0777, true); - @mkdir($path_site . "files/", 0777, true); - @mkdir($path_site . "mailTemplates/", 0777, true); - @mkdir($path_site . "public/", 0777, true); - @mkdir($path_site . "reports/", 0777, true); - @mkdir($path_site . "xmlForms", 0777, true); - - $dbText = "installLog("Creating: " . $db_file ); - file_put_contents ( $db_file, $dbText); - - // Generate the databases.php file - $databases_file = $path_site . 'databases.php'; - $dbData = sprintf("\$dbAdapter = '%s';\n", 'mysql'); - $dbData .= sprintf("\$dbHost = '%s';\n", $db_host); - $dbData .= sprintf("\$dbName = '%s';\n", $wf); - $dbData .= sprintf("\$dbUser = '%s';\n", $wf); - $dbData .= sprintf("\$dbPass = '%s';\n", $wfPass); - $dbData .= sprintf("\$dbRbacHost = '%s';\n", $db_host); - $dbData .= sprintf("\$dbRbacName = '%s';\n", $rb); - $dbData .= sprintf("\$dbRbacUser = '%s';\n", $rb); - $dbData .= sprintf("\$dbRbacPass = '%s';\n", $rbPass); - $dbData .= sprintf("\$dbReportHost = '%s';\n", $db_host); - $dbData .= sprintf("\$dbReportName = '%s';\n", $rp); - $dbData .= sprintf("\$dbReportUser = '%s';\n", $rp); - $dbData .= sprintf("\$dbReportPass = '%s';\n", $rpPass); - $databasesText = str_replace('{dbData}', $dbData, @file_get_contents(PATH_HOME . 'engine/templates/installer/databases.tpl')); - - $this->installLog('Creating: ' . $databases_file); - file_put_contents($databases_file, $databasesText); + /** + * query_sql_file send many statements to server + * + * @param string $file + * @param string $connection + * @return array $report + */ + public function mysqlFileQuery ($file) + { + if (! is_file( $file )) { + throw (new Exception( sprintf( "File $file is not a valid sql file", $file ) )); + return $false; + } + $this->installLog( 'Procesing: ' . $file ); + $startTime = microtime( true ); + // $content = file_get_contents($file); + // $queries = explode(';', $content); - // Execute scripts to create and populates databases - $query = sprintf ( "USE %s;", $rb ); - $this->mysqlQuery( $query ); + // foreach( $queries as $sql) { + // if (trim($sql) != '') { + // $query = @mysql_query($sql, $this->link); + // if (!$query) { + // $errorMessage = mysql_error($this->link); - $this->mysqlFileQuery ( PATH_RBAC_HOME . 'engine/data/mysql/schema.sql' ); - $this->mysqlFileQuery ( PATH_RBAC_HOME . 'engine/data/mysql/insert.sql' ); - $query = sprintf ( "USE %s;", $wf ); - $this->mysqlQuery( $query ); - $this->mysqlFileQuery ( PATH_HOME . 'engine/data/mysql/schema.sql' ); - $this->mysqlFileQuery ( PATH_HOME . 'engine/data/mysql/insert.sql' ); + // $this->installLog ( sprintf ( 'MySQL error: %s Query: %s ', $errorMessage, $sql ) ); + // throw ( new Exception ( $errorMessage ) ); + // return false; + // } + // } + // } - // Create the triggers - if (file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql') && - file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql') && - file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql') && - file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql') && - file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql')) { - $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql')); - $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql')); - $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql')); - $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql')); - $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql')); - $this->mysqlQuery("INSERT INTO `CONFIGURATION` ( + + //erik: New Update, to support more complex queries + + + $lines = file( $file ); + $previous = null; + $errors = ''; + @mysql_query( "SET NAMES 'utf8';" ); + foreach ($lines as $j => $line) { + $line = trim( $line ); // Remove comments from the script + + + if (strpos( $line, "--" ) === 0) { + $line = substr( $line, 0, strpos( $line, "--" ) ); + } + + if (empty( $line )) { + continue; + } + + if (strpos( $line, "#" ) === 0) { + $line = substr( $line, 0, strpos( $line, "#" ) ); + } + + if (empty( $line )) { + continue; + } + + // Concatenate the previous line, if any, with the current + if ($previous) { + $line = $previous . " " . $line; + } + $previous = null; + + // If the current line doesnt end with ; then put this line together + // with the next one, thus supporting multi-line statements. + if (strrpos( $line, ";" ) != strlen( $line ) - 1) { + $previous = $line; + continue; + } + + $line = substr( $line, 0, strrpos( $line, ";" ) ); + @mysql_query( $line, $this->link ); + } + + $endTime = microtime( true ); + $this->installLog( sprintf( 'File: %s processed in %3.2f seconds', basename( $file ), $endTime - $startTime ) ); + return true; + } + + /** + * query_sql_file send many statements to server + * + * @param string $file + * @param string $connection + * @return array $report + */ + public function mssqlFileQuery ($file) + { + if (! is_file( $file )) { + throw (new Exception( sprintf( "File $file is not a valid sql file", $file ) )); + return $false; + } + $this->installLog( 'Procesing: ' . $file ); + $startTime = microtime( true ); + $content = file_get_contents( $file ); + $queries = explode( ';', $content ); + + foreach ($queries as $sql) { + $query = @mssql_query( $sql, $this->link ); + if (! $query) { + $errorMessage = mssql_get_last_message(); + + $this->installLog( sprintf( 'MSSQL error: %s Query: %s ', $errorMessage, $sql ) ); + throw (new Exception( $errorMessage )); + return false; + } + } + $endTime = microtime( true ); + $this->installLog( sprintf( 'File: %s processed in %3.2f seconds', basename( $file ), $endTime - $startTime ) ); + return true; + } + + /** + * set Grant Privileges for MySQL + * + * @param string $psUser + * @param string $psPassword + * @param string $psDatabase + * @return void + */ + public function setGrantPrivilegesMySQL ($psUser, $psPassword, $psDatabase, $host) + { + $host = ($host == 'localhost' || $host == '127.0.0.1' ? 'localhost' : '%'); + $query = sprintf( "GRANT ALL PRIVILEGES ON `%s`.* TO %s@'%s' IDENTIFIED BY '%s' WITH GRANT OPTION", $psDatabase, $psUser, $host, $psPassword ); + $this->mysqlQuery( $query ); + } + + /** + * set Grant Privileges for SQLServer + * + * @param string $psUser + * @param string $psPassword + * @param string $psDatabase + * @return void + */ + public function setGrantPrivilegesMSSQL ($psUser, $psPassword, $psDatabase) + { + + $query = sprintf( "IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'%s') DROP LOGIN [%s]", $psUser, $psUser ); + $this->mssqlQuery( $query ); + + $query = sprintf( "CREATE LOGIN [%s] WITH PASSWORD=N'%s', DEFAULT_DATABASE=[%s], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF ", $psUser, $psPassword, $psDatabase ); + $this->mssqlQuery( $query ); + + $query = sprintf( "USE %s;", $psDatabase ); + $this->mssqlQuery( $query ); + + $query = sprintf( "IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'%s') DROP USER [%s]", $psUser, $psUser ); + $this->mssqlQuery( $query ); + + $query = sprintf( "CREATE USER %s FOR LOGIN %s;", $psUser, $psUser ); + $this->mssqlQuery( $query ); + + $query = sprintf( "sp_addrolemember 'db_owner', '%s' ", $psUser ); + $this->mssqlQuery( $query ); + + $query = sprintf( "sp_addrolemember 'db_ddladmin', '%s' ", $psUser ); + $this->mssqlQuery( $query ); + + $query = sprintf( "sp_addrolemember 'db_accessadmin', '%s' ", $psUser ); + $this->mssqlQuery( $query ); + + $query = sprintf( "use master " ); + $this->mssqlQuery( $query ); + + return true; + } + + public function createMySQLWorkspace () + { + ini_set( 'max_execution_time', '0' ); + $info->result = false; + $info->message = ''; + $info->canRedirect = true; + + $db_hostname = trim( $_REQUEST['db_hostname'] ); + $db_port = trim( $_REQUEST['db_port'] ); + $db_username = trim( $_REQUEST['db_username'] ); + $db_password = trim( $_REQUEST['db_password'] ); + $wf = trim( $_REQUEST['wfDatabase'] ); + $rb = trim( $_REQUEST['rbDatabase'] ); + $rp = trim( $_REQUEST['rpDatabase'] ); + $workspace = trim( $_REQUEST['workspace'] ); + $pathConfig = trim( $_REQUEST['pathConfig'] ); + $pathLanguages = trim( $_REQUEST['pathLanguages'] ); + $pathPlugins = trim( $_REQUEST['pathPlugins'] ); + $pathShared = trim( $_REQUEST['pathShared'] ); + $pathXmlforms = trim( $_REQUEST['pathXmlforms'] ); + $adminPassword = trim( $_REQUEST['adminPassword'] ); + $adminUsername = trim( $_REQUEST['adminUsername'] ); + $deleteDB = ($_REQUEST['deleteDB'] == 'true'); + + if (substr( $pathShared, - 1 ) != '/') { + $pathShared .= '/'; + } + + $this->installLog( '-------------------------------------------' ); + $this->installLog( sprintf( "Creating workspace '%s' ", $workspace ) ); + + try { + $db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname; + $this->link = @mysql_connect( $db_host, $db_username, $db_password ); + $this->installLog( sprintf( "Connected to server %s:%d using user: '%s' ", $db_hostname, $db_port, $db_username ) ); + + if ($deleteDB) { + $q = sprintf( 'DROP DATABASE IF EXISTS %s;', $wf, $wf ); + $this->mysqlQuery( $q ); + + $q = sprintf( 'DROP DATABASE IF EXISTS %s;', $rb, $rb ); + $this->mysqlQuery( $q ); + + $q = sprintf( 'DROP DATABASE IF EXISTS %s;', $rp, $rp ); + $this->mysqlQuery( $q ); + } + + // CREATE databases wf_workflow, rb_workflow and rp_workflow + $q = sprintf( 'CREATE DATABASE IF NOT EXISTS %s;', $wf, $wf ); + $this->mysqlQuery( $q ); + + $q = sprintf( 'CREATE DATABASE IF NOT EXISTS %s;', $rb, $rb ); + $this->mysqlQuery( $q ); + + $q = sprintf( 'CREATE DATABASE IF NOT EXISTS %s;', $rp, $rp ); + $this->mysqlQuery( $q ); + + // CREATE users and GRANT Privileges + $wfPass = G::generate_password( 12 ); + $rbPass = G::generate_password( 12 ); + $rpPass = G::generate_password( 12 ); + $this->setGrantPrivilegesMySQL( $wf, $wfPass, $wf, $db_hostname ); + $this->setGrantPrivilegesMySQL( $rb, $rbPass, $rb, $db_hostname ); + $this->setGrantPrivilegesMySQL( $rp, $rpPass, $rp, $db_hostname ); + + // Generate the db.php file and folders + $path_site = $pathShared . "/sites/" . $workspace . "/"; + $db_file = $path_site . "db.php"; + @mkdir( $path_site, 0777, true ); + @mkdir( $path_site . "files/", 0777, true ); + @mkdir( $path_site . "mailTemplates/", 0777, true ); + @mkdir( $path_site . "public/", 0777, true ); + @mkdir( $path_site . "reports/", 0777, true ); + @mkdir( $path_site . "xmlForms", 0777, true ); + + $dbText = "installLog( "Creating: " . $db_file ); + file_put_contents( $db_file, $dbText ); + + // Generate the databases.php file + $databases_file = $path_site . 'databases.php'; + $dbData = sprintf( "\$dbAdapter = '%s';\n", 'mysql' ); + $dbData .= sprintf( "\$dbHost = '%s';\n", $db_host ); + $dbData .= sprintf( "\$dbName = '%s';\n", $wf ); + $dbData .= sprintf( "\$dbUser = '%s';\n", $wf ); + $dbData .= sprintf( "\$dbPass = '%s';\n", $wfPass ); + $dbData .= sprintf( "\$dbRbacHost = '%s';\n", $db_host ); + $dbData .= sprintf( "\$dbRbacName = '%s';\n", $rb ); + $dbData .= sprintf( "\$dbRbacUser = '%s';\n", $rb ); + $dbData .= sprintf( "\$dbRbacPass = '%s';\n", $rbPass ); + $dbData .= sprintf( "\$dbReportHost = '%s';\n", $db_host ); + $dbData .= sprintf( "\$dbReportName = '%s';\n", $rp ); + $dbData .= sprintf( "\$dbReportUser = '%s';\n", $rp ); + $dbData .= sprintf( "\$dbReportPass = '%s';\n", $rpPass ); + $databasesText = str_replace( '{dbData}', $dbData, @file_get_contents( PATH_HOME . 'engine/templates/installer/databases.tpl' ) ); + + $this->installLog( 'Creating: ' . $databases_file ); + file_put_contents( $databases_file, $databasesText ); + + // Execute scripts to create and populates databases + $query = sprintf( "USE %s;", $rb ); + $this->mysqlQuery( $query ); + + $this->mysqlFileQuery( PATH_RBAC_HOME . 'engine/data/mysql/schema.sql' ); + $this->mysqlFileQuery( PATH_RBAC_HOME . 'engine/data/mysql/insert.sql' ); + + $query = sprintf( "USE %s;", $wf ); + $this->mysqlQuery( $query ); + $this->mysqlFileQuery( PATH_HOME . 'engine/data/mysql/schema.sql' ); + $this->mysqlFileQuery( PATH_HOME . 'engine/data/mysql/insert.sql' ); + + // Create the triggers + if (file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql' )) { + $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql' ) ); + $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql' ) ); + $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql' ) ); + $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql' ) ); + $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql' ) ); + $this->mysqlQuery( "INSERT INTO `CONFIGURATION` ( `CFG_UID`, `CFG_VALUE` ) VALUES ( 'APP_CACHE_VIEW_ENGINE', - '" . mysql_real_escape_string(serialize(array('LANG' => 'en', 'STATUS' => 'active'))) . "' - )"); - } + '" . mysql_real_escape_string( serialize( array ('LANG' => 'en','STATUS' => 'active' + ) ) ) . "' + )" ); + } - // Change admin user - $query = sprintf ( "USE %s;", $wf ); - $this->mysqlQuery( $query ); + // Change admin user + $query = sprintf( "USE %s;", $wf ); + $this->mysqlQuery( $query ); - $query = sprintf ( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5($adminPassword) ); - $this->mysqlQuery( $query ); + $query = sprintf( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5( $adminPassword ) ); + $this->mysqlQuery( $query ); - $query = sprintf ( "USE %s;", $rb ); - $this->mysqlQuery( $query ); + $query = sprintf( "USE %s;", $rb ); + $this->mysqlQuery( $query ); - $query = sprintf ( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5($adminPassword) ); - $this->mysqlQuery( $query ); + $query = sprintf( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5( $adminPassword ) ); + $this->mysqlQuery( $query ); - // Write the paths_installed.php file (contains all the information configured so far) - if ( !file_exists(FILE_PATHS_INSTALLED) ) { - $sh = md5( filemtime( PATH_GULLIVER . '/class.g.php' ) ); - $h = G::encrypt($db_hostname.$sh.$db_username.$sh.$db_password, $sh); - $dbText = "installLog("Creating: " . FILE_PATHS_INSTALLED ); - file_put_contents ( FILE_PATHS_INSTALLED, $dbText); - } + // Write the paths_installed.php file (contains all the information configured so far) + if (! file_exists( FILE_PATHS_INSTALLED )) { + $sh = md5( filemtime( PATH_GULLIVER . '/class.g.php' ) ); + $h = G::encrypt( $db_hostname . $sh . $db_username . $sh . $db_password, $sh ); + $dbText = "installLog( "Creating: " . FILE_PATHS_INSTALLED ); + file_put_contents( FILE_PATHS_INSTALLED, $dbText ); + } - /** - * AppCacheView Build - */ - define('HASH_INSTALLATION', $h ); - define('SYSTEM_HASH', $sh ); - define('PATH_DB', $pathShared . 'sites' . PATH_SEP ); - define('SYS_SYS', 'workflow'); + /** + * AppCacheView Build + */ + define( 'HASH_INSTALLATION', $h ); + define( 'SYSTEM_HASH', $sh ); + define( 'PATH_DB', $pathShared . 'sites' . PATH_SEP ); + define( 'SYS_SYS', 'workflow' ); - require_once("propel/Propel.php"); + require_once ("propel/Propel.php"); - Propel::init( PATH_CORE . "config/databases.php" ); - $con = Propel::getConnection('workflow'); + Propel::init( PATH_CORE . "config/databases.php" ); + $con = Propel::getConnection( 'workflow' ); - require_once('classes/model/AppCacheView.php'); - $lang='en'; + require_once ('classes/model/AppCacheView.php'); + $lang = 'en'; - //setup the appcacheview object, and the path for the sql files - $appCache = new AppCacheView(); + //setup the appcacheview object, and the path for the sql files + $appCache = new AppCacheView(); - $appCache->setPathToAppCacheFiles ( PATH_METHODS . 'setup' . PATH_SEP .'setupSchemas'. PATH_SEP ); + $appCache->setPathToAppCacheFiles( PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP ); - //APP_DELEGATION INSERT - $res = $appCache->triggerAppDelegationInsert($lang, true); + //APP_DELEGATION INSERT + $res = $appCache->triggerAppDelegationInsert( $lang, true ); - //APP_DELEGATION Update - $res = $appCache->triggerAppDelegationUpdate($lang, true); + //APP_DELEGATION Update + $res = $appCache->triggerAppDelegationUpdate( $lang, true ); - //APPLICATION UPDATE - $res = $appCache->triggerApplicationUpdate($lang, true); + //APPLICATION UPDATE + $res = $appCache->triggerApplicationUpdate( $lang, true ); - //APPLICATION DELETE - $res = $appCache->triggerApplicationDelete($lang, true); + //APPLICATION DELETE + $res = $appCache->triggerApplicationDelete( $lang, true ); - //CONTENT UPDATE - $res = $appCache->triggerContentUpdate($lang, true); + //CONTENT UPDATE + $res = $appCache->triggerContentUpdate( $lang, true ); - //build using the method in AppCacheView Class - $res = $appCache->fillAppCacheView($lang); + //build using the method in AppCacheView Class + $res = $appCache->fillAppCacheView( $lang ); - //end AppCacheView Build + //end AppCacheView Build - //erik: for new env conf handling - G::loadClass('system'); - $envFile = PATH_CONFIG . 'env.ini'; - //writting for new installtions to use the classic skin - $updatedConf['default_skin'] = 'classic'; - $info->uri = '/sys' . $_REQUEST['workspace'] . '/en/classic/login/login'; + //erik: for new env conf handling + G::loadClass( 'system' ); + $envFile = PATH_CONFIG . 'env.ini'; - try { - G::update_php_ini($envFile, $updatedConf); - } - catch (Exception $e) { - $info->result = false; - $info->message = "ProcessMaker couldn't write on configuration file: $envFile.
"; - $info->message .= "The new ProcessMaker UI couldn't be applied on installation, you can enable it after from Admin->System settings."; - $this->installLog("Installed but with error, couldn't update env.ini" ); + //writting for new installtions to use the classic skin + $updatedConf['default_skin'] = 'classic'; + $info->uri = '/sys' . $_REQUEST['workspace'] . '/en/classic/login/login'; + + try { + G::update_php_ini( $envFile, $updatedConf ); + } catch (Exception $e) { + $info->result = false; + $info->message = "ProcessMaker couldn't write on configuration file: $envFile.
"; + $info->message .= "The new ProcessMaker UI couldn't be applied on installation, you can enable it after from Admin->System settings."; + $this->installLog( "Installed but with error, couldn't update env.ini" ); + return $info; + } + + // getting configuration from env.ini + $sysConf = System::getSystemConfiguration( $envFile ); + + try { + // update the main index file + $indexFileUpdated = System::updateIndexFile( array ('lang' => 'en','skin' => $updatedConf['default_skin'] + ) ); + } catch (Exception $e) { + $info->result = false; + $info->message = "ProcessMaker couldn't write on configuration file: " . PATH_HTML . "index.html.
"; + $info->message .= "The new ProcessMaker UI couldn't be applied on installation, you can enable it after from Admin->System settings."; + $this->installLog( "Installed but with error, couldn't update index.html" ); + return $info; + } + + $this->installLog( "Index File updated $indexFileUpdated with lang: {$sysConf['default_lang']}, skin: {$sysConf['default_skin']} " ); + $this->installLog( "Install completed Succesfully" ); + + $info->result = true; + $info->message = 'Succesfully OK'; + } catch (Exception $e) { + $info->canRedirect = false; + $info->result = false; + $info->message = $e->getMessage(); + } return $info; - } - - // getting configuration from env.ini - $sysConf = System::getSystemConfiguration($envFile); - - try { - // update the main index file - $indexFileUpdated = System::updateIndexFile(array( - 'lang' => 'en', - 'skin' => $updatedConf['default_skin'] - )); - } - catch (Exception $e) { - $info->result = false; - $info->message = "ProcessMaker couldn't write on configuration file: ".PATH_HTML."index.html.
"; - $info->message .= "The new ProcessMaker UI couldn't be applied on installation, you can enable it after from Admin->System settings."; - $this->installLog("Installed but with error, couldn't update index.html" ); - return $info; - } - - $this->installLog("Index File updated $indexFileUpdated with lang: {$sysConf['default_lang']}, skin: {$sysConf['default_skin']} " ); - $this->installLog("Install completed Succesfully" ); - - $info->result = true; - $info->message = 'Succesfully OK'; } - catch (Exception $e) { - $info->canRedirect = false; - $info->result = false; - $info->message = $e->getMessage(); - } - return $info; - } - public function createMSSQLWorkspace() - { - ini_set('max_execution_time', '0'); - $info->result = false; - $info->message = ''; + public function createMSSQLWorkspace () + { + ini_set( 'max_execution_time', '0' ); + $info->result = false; + $info->message = ''; - $db_hostname = trim($_REQUEST['db_hostname']); - $db_port = trim($_REQUEST['db_port']); - $db_username = trim($_REQUEST['db_username']); - $db_password = trim($_REQUEST['db_password']); - $wf = trim($_REQUEST['wfDatabase']); - $rb = trim($_REQUEST['rbDatabase']); - $rp = trim($_REQUEST['rpDatabase']); - $workspace = trim($_REQUEST['workspace']); - $pathConfig = trim($_REQUEST['pathConfig']); - $pathLanguages = trim($_REQUEST['pathLanguages']); - $pathPlugins = trim($_REQUEST['pathPlugins']); - $pathShared = trim($_REQUEST['pathShared']); - $pathXmlforms = trim($_REQUEST['pathXmlforms']); - $adminPassword = trim($_REQUEST['adminPassword']); - $adminUsername = trim($_REQUEST['adminUsername']); - $deleteDB = ($_REQUEST['deleteDB'] == 'true'); + $db_hostname = trim( $_REQUEST['db_hostname'] ); + $db_port = trim( $_REQUEST['db_port'] ); + $db_username = trim( $_REQUEST['db_username'] ); + $db_password = trim( $_REQUEST['db_password'] ); + $wf = trim( $_REQUEST['wfDatabase'] ); + $rb = trim( $_REQUEST['rbDatabase'] ); + $rp = trim( $_REQUEST['rpDatabase'] ); + $workspace = trim( $_REQUEST['workspace'] ); + $pathConfig = trim( $_REQUEST['pathConfig'] ); + $pathLanguages = trim( $_REQUEST['pathLanguages'] ); + $pathPlugins = trim( $_REQUEST['pathPlugins'] ); + $pathShared = trim( $_REQUEST['pathShared'] ); + $pathXmlforms = trim( $_REQUEST['pathXmlforms'] ); + $adminPassword = trim( $_REQUEST['adminPassword'] ); + $adminUsername = trim( $_REQUEST['adminUsername'] ); + $deleteDB = ($_REQUEST['deleteDB'] == 'true'); - if ( substr($pathShared,-1) != '/' ) $pathShared .= '/'; + if (substr( $pathShared, - 1 ) != '/') { + $pathShared .= '/'; + } - $this->installLog ( '-------------------------------------------' ); - $this->installLog ( sprintf ( "Creating workspace '%s' ", $workspace) ); + $this->installLog( '-------------------------------------------' ); + $this->installLog( sprintf( "Creating workspace '%s' ", $workspace ) ); - try { - $db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname ; - $this->link = @mssql_connect($db_host, $db_username, $db_password); - $this->installLog (sprintf ( "Connected to server %s:%d using user: '%s' ", $db_hostname, $db_port, $db_username ) ); + try { + $db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname; + $this->link = @mssql_connect( $db_host, $db_username, $db_password ); + $this->installLog( sprintf( "Connected to server %s:%d using user: '%s' ", $db_hostname, $db_port, $db_username ) ); - $this->mssqlQuery( 'USE [master]' ); + $this->mssqlQuery( 'USE [master]' ); - // DROP databases wf_workflow, rb_workflow and rp_workflow - if ($deleteDB) { - $q = sprintf ("IF EXISTS (SELECT name FROM sys.databases WHERE name='%s' ) DROP DATABASE %s" , $wf, $wf ); - $this->mssqlQuery( $q); + // DROP databases wf_workflow, rb_workflow and rp_workflow + if ($deleteDB) { + $q = sprintf( "IF EXISTS (SELECT name FROM sys.databases WHERE name='%s' ) DROP DATABASE %s", $wf, $wf ); + $this->mssqlQuery( $q ); - $q = sprintf ("IF EXISTS (SELECT name FROM sys.databases WHERE name='%s' ) DROP DATABASE %s" , $rb, $rb ); - $this->mssqlQuery( $q); + $q = sprintf( "IF EXISTS (SELECT name FROM sys.databases WHERE name='%s' ) DROP DATABASE %s", $rb, $rb ); + $this->mssqlQuery( $q ); - $q = sprintf ("IF EXISTS (SELECT name FROM sys.databases WHERE name='%s' ) DROP DATABASE %s" , $rp, $rp ); - $this->mssqlQuery( $q); - } + $q = sprintf( "IF EXISTS (SELECT name FROM sys.databases WHERE name='%s' ) DROP DATABASE %s", $rp, $rp ); + $this->mssqlQuery( $q ); + } - // CREATE databases wf_workflow, rb_workflow and rp_workflow - $q = sprintf ("IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='%s' ) CREATE DATABASE %s" , $wf, $wf ); - $this->mssqlQuery( $q); + // CREATE databases wf_workflow, rb_workflow and rp_workflow + $q = sprintf( "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='%s' ) CREATE DATABASE %s", $wf, $wf ); + $this->mssqlQuery( $q ); - $q = sprintf ("IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='%s' ) CREATE DATABASE %s" , $rb, $rb ); - $this->mssqlQuery( $q); + $q = sprintf( "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='%s' ) CREATE DATABASE %s", $rb, $rb ); + $this->mssqlQuery( $q ); - $q = sprintf ("IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='%s' ) CREATE DATABASE %s" , $rp, $rp ); - $this->mssqlQuery( $q); + $q = sprintf( "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='%s' ) CREATE DATABASE %s", $rp, $rp ); + $this->mssqlQuery( $q ); - //CREATE users and GRANT Privileges - $wfPass = G::generate_password(12); - $rbPass = G::generate_password(12); - $rpPass = G::generate_password(12); - $this->setGrantPrivilegesMSSQL($wf, $wfPass, $wf ); - $this->setGrantPrivilegesMSSQL($rb, $rbPass, $rb ); - $this->setGrantPrivilegesMSSQL($rp, $rpPass, $rp ); + //CREATE users and GRANT Privileges + $wfPass = G::generate_password( 12 ); + $rbPass = G::generate_password( 12 ); + $rpPass = G::generate_password( 12 ); + $this->setGrantPrivilegesMSSQL( $wf, $wfPass, $wf ); + $this->setGrantPrivilegesMSSQL( $rb, $rbPass, $rb ); + $this->setGrantPrivilegesMSSQL( $rp, $rpPass, $rp ); - //Generate the db.php file and folders - $path_site = $pathShared . "/sites/" . $workspace ."/"; - $db_file = $path_site. "db.php"; - mkdir($path_site, 0777, true); - @mkdir($path_site . "files/", 0777, true); - @mkdir($path_site . "mailTemplates/", 0777, true); - @mkdir($path_site . "public/", 0777, true); - @mkdir($path_site . "reports/", 0777, true); - @mkdir($path_site . "xmlForms", 0777, true); + //Generate the db.php file and folders + $path_site = $pathShared . "/sites/" . $workspace . "/"; + $db_file = $path_site . "db.php"; + mkdir( $path_site, 0777, true ); + @mkdir( $path_site . "files/", 0777, true ); + @mkdir( $path_site . "mailTemplates/", 0777, true ); + @mkdir( $path_site . "public/", 0777, true ); + @mkdir( $path_site . "reports/", 0777, true ); + @mkdir( $path_site . "xmlForms", 0777, true ); - $dbText = "installLog("Creating: " . $db_file ); - file_put_contents ( $db_file, $dbText); + $this->installLog( "Creating: " . $db_file ); + file_put_contents( $db_file, $dbText ); - // Generate the databases.php file - $databases_file = $path_site . 'databases.php'; - $dbData = sprintf("\$dbAdapter = '%s';\n", 'mssql'); - $dbData .= sprintf("\$dbHost = '%s';\n", $db_host); - $dbData .= sprintf("\$dbName = '%s';\n", $wf); - $dbData .= sprintf("\$dbUser = '%s';\n", $wf); - $dbData .= sprintf("\$dbPass = '%s';\n", $wfPass); - $dbData .= sprintf("\$dbRbacHost = '%s';\n", $db_host); - $dbData .= sprintf("\$dbRbacName = '%s';\n", $rb); - $dbData .= sprintf("\$dbRbacUser = '%s';\n", $rb); - $dbData .= sprintf("\$dbRbacPass = '%s';\n", $rbPass); - $dbData .= sprintf("\$dbReportHost = '%s';\n", $db_host); - $dbData .= sprintf("\$dbReportName = '%s';\n", $rp); - $dbData .= sprintf("\$dbReportUser = '%s';\n", $rp); - $dbData .= sprintf("\$dbReportPass = '%s';\n", $rpPass); - $databasesText = str_replace('{dbData}', $dbData, @file_get_contents(PATH_HOME . 'engine/templates/installer/databases.tpl')); + // Generate the databases.php file + $databases_file = $path_site . 'databases.php'; + $dbData = sprintf( "\$dbAdapter = '%s';\n", 'mssql' ); + $dbData .= sprintf( "\$dbHost = '%s';\n", $db_host ); + $dbData .= sprintf( "\$dbName = '%s';\n", $wf ); + $dbData .= sprintf( "\$dbUser = '%s';\n", $wf ); + $dbData .= sprintf( "\$dbPass = '%s';\n", $wfPass ); + $dbData .= sprintf( "\$dbRbacHost = '%s';\n", $db_host ); + $dbData .= sprintf( "\$dbRbacName = '%s';\n", $rb ); + $dbData .= sprintf( "\$dbRbacUser = '%s';\n", $rb ); + $dbData .= sprintf( "\$dbRbacPass = '%s';\n", $rbPass ); + $dbData .= sprintf( "\$dbReportHost = '%s';\n", $db_host ); + $dbData .= sprintf( "\$dbReportName = '%s';\n", $rp ); + $dbData .= sprintf( "\$dbReportUser = '%s';\n", $rp ); + $dbData .= sprintf( "\$dbReportPass = '%s';\n", $rpPass ); + $databasesText = str_replace( '{dbData}', $dbData, @file_get_contents( PATH_HOME . 'engine/templates/installer/databases.tpl' ) ); - $this->installLog('Creating: ' . $databases_file); - file_put_contents($databases_file, $databasesText); + $this->installLog( 'Creating: ' . $databases_file ); + file_put_contents( $databases_file, $databasesText ); - //execute scripts to create and populates databases - $query = sprintf ( "USE %s;", $rb ); - $this->mssqlQuery( $query ); + //execute scripts to create and populates databases + $query = sprintf( "USE %s;", $rb ); + $this->mssqlQuery( $query ); - $this->mssqlFileQuery ( PATH_RBAC_HOME . 'engine/data/mssql/schema.sql' ); - $this->mssqlFileQuery ( PATH_RBAC_HOME . 'engine/data/mssql/insert.sql' ); + $this->mssqlFileQuery( PATH_RBAC_HOME . 'engine/data/mssql/schema.sql' ); + $this->mssqlFileQuery( PATH_RBAC_HOME . 'engine/data/mssql/insert.sql' ); - $query = sprintf ( "USE %s;", $wf ); - $this->mssqlQuery( $query ); - $this->mssqlFileQuery ( PATH_HOME . 'engine/data/mssql/schema.sql' ); - $this->mssqlFileQuery ( PATH_HOME . 'engine/data/mssql/insert.sql' ); + $query = sprintf( "USE %s;", $wf ); + $this->mssqlQuery( $query ); + $this->mssqlFileQuery( PATH_HOME . 'engine/data/mssql/schema.sql' ); + $this->mssqlFileQuery( PATH_HOME . 'engine/data/mssql/insert.sql' ); - // Create the triggers - if (file_exists(PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationInsert.sql') && - file_exists(PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationUpdate.sql') && - file_exists(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationUpdate.sql') && - file_exists(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationDelete.sql') && - file_exists(PATH_HOME . 'engine/plugins/enterprise/data/triggerContentUpdate.sql')) { - $this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationInsert.sql')); - $this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationUpdate.sql')); - $this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationUpdate.sql')); - $this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationDelete.sql')); - $this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerContentUpdate.sql')); - $this->mssqlQuery("INSERT INTO CONFIGURATION ( + // Create the triggers + if (file_exists( PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationInsert.sql' ) && file_exists( PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationUpdate.sql' ) && file_exists( PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationUpdate.sql' ) && file_exists( PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationDelete.sql' ) && file_exists( PATH_HOME . 'engine/plugins/enterprise/data/triggerContentUpdate.sql' )) { + $this->mssqlQuery( @file_get_contents( PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationInsert.sql' ) ); + $this->mssqlQuery( @file_get_contents( PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationUpdate.sql' ) ); + $this->mssqlQuery( @file_get_contents( PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationUpdate.sql' ) ); + $this->mssqlQuery( @file_get_contents( PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationDelete.sql' ) ); + $this->mssqlQuery( @file_get_contents( PATH_HOME . 'engine/plugins/enterprise/data/triggerContentUpdate.sql' ) ); + $this->mssqlQuery( "INSERT INTO CONFIGURATION ( CFG_UID, CFG_VALUE ) VALUES ( 'APP_CACHE_VIEW_ENGINE', - '" . addslashes(serialize(array('LANG' => 'en', 'STATUS' => 'active'))) . "' - )"); - } + '" . addslashes( serialize( array ('LANG' => 'en','STATUS' => 'active' + ) ) ) . "' + )" ); + } - //change admin user - $query = sprintf ( "USE %s;", $wf ); - $this->mssqlQuery( $query ); + //change admin user + $query = sprintf( "USE %s;", $wf ); + $this->mssqlQuery( $query ); - $query = sprintf ( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5($adminPassword) ); - $this->mssqlQuery( $query ); + $query = sprintf( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5( $adminPassword ) ); + $this->mssqlQuery( $query ); - $query = sprintf ( "USE %s;", $rb ); - $this->mssqlQuery( $query ); + $query = sprintf( "USE %s;", $rb ); + $this->mssqlQuery( $query ); - $query = sprintf ( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5($adminPassword) ); - $this->mssqlQuery( $query ); + $query = sprintf( "UPDATE USERS SET USR_USERNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5( $adminPassword ) ); + $this->mssqlQuery( $query ); - // Write the paths_installed.php file (contains all the information configured so far) - if ( !file_exists(FILE_PATHS_INSTALLED) ) { - $sh = md5( filemtime( PATH_GULLIVER . '/class.g.php' ) ); - $h = G::encrypt($db_hostname.$sh.$db_username.$sh.$db_password.'1' , $sh); - $dbText = "installLog("Creating: " . FILE_PATHS_INSTALLED ); - file_put_contents ( FILE_PATHS_INSTALLED, $dbText); - } - $this->installLog("Install completed Succesfully" ); - $info->result = true; - $info->message = 'Succesfully'; - $info->url = '/sys' . $_REQUEST['workspace'] . '/en/classic/main/login'; - } - catch (Exception $e) { - $info->result = false; - $info->message = $e->getMessage(); - } - return $info; - } - - public function getEngines() - { - $this->setResponseType('json'); - $engines = array(); - if (function_exists('mysql_query')) { - $engine = new stdclass(); - $engine->id = 'mysql'; - $engine->label = 'MySQL'; - $engines[] = $engine; - } - /** DISABLED TEMPORARELY - if (function_exists('mssql_query')) { - $engine = new stdclass(); - $engine->id = 'mssql'; - $engine->label = 'Microsoft SQL Server'; - $engines[] = $engine; - }*/ - return $engines; - } - - public function checkDatabases() - { - $this->setResponseType('json'); - $info = new stdclass(); - - if ($_REQUEST['db_engine'] == 'mysql') { - $link = @mysql_connect($_REQUEST['db_hostname'], $_REQUEST['db_username'], $_REQUEST['db_password']); - $dataset = @mysql_query("show databases like '" . $_REQUEST['wfDatabase'] . "'", $link); - $info->wfDatabaseExists = (@mysql_num_rows($dataset) > 0); - $dataset = @mysql_query("show databases like '" . $_REQUEST['rbDatabase'] . "'", $link); - $info->rbDatabaseExists = (@mysql_num_rows($dataset) > 0); - $dataset = @mysql_query("show databases like '" . $_REQUEST['rpDatabase'] . "'", $link); - $info->rpDatabaseExists = (@mysql_num_rows($dataset) > 0); - } - else { - $link = @mssql_connect($_REQUEST['db_hostname'], $_REQUEST['db_username'], $_REQUEST['db_password']); - $dataset = @mssql_query("select * from sys.databases where name = '" . $_REQUEST['wfDatabase'] . "'", $link); - $info->wfDatabaseExists = (@mssql_num_rows($dataset) > 0); - $dataset = @mssql_query("select * from sys.databases where name = '" . $_REQUEST['rbDatabase'] . "'", $link); - $info->rbDatabaseExists = (@mssql_num_rows($dataset) > 0); - $dataset = @mssql_query("select * from sys.databases where name = '" . $_REQUEST['rpDatabase'] . "'", $link); - $info->rpDatabaseExists = (@mssql_num_rows($dataset) > 0); + // Write the paths_installed.php file (contains all the information configured so far) + if (! file_exists( FILE_PATHS_INSTALLED )) { + $sh = md5( filemtime( PATH_GULLIVER . '/class.g.php' ) ); + $h = G::encrypt( $db_hostname . $sh . $db_username . $sh . $db_password . '1', $sh ); + $dbText = "installLog( "Creating: " . FILE_PATHS_INSTALLED ); + file_put_contents( FILE_PATHS_INSTALLED, $dbText ); + } + $this->installLog( "Install completed Succesfully" ); + $info->result = true; + $info->message = 'Succesfully'; + $info->url = '/sys' . $_REQUEST['workspace'] . '/en/classic/main/login'; + } catch (Exception $e) { + $info->result = false; + $info->message = $e->getMessage(); + } + return $info; } - $info->errMessage = 'Database already exists, check "Delete Databases if exists" to overwrite the exiting databases.'; - - return $info; - } - - /** - * Privates functions section, non callable by http request - */ - - private function testMySQLconnection() - { - $info->result = false; - $info->message = ''; - if ( !function_exists("mysql_connect") ) { - $info->message = 'php-mysql is Not Installed'; - return $info; - } - $db_hostname = $_REQUEST['db_hostname']; - $db_port = $_REQUEST['db_port']; - $db_username = $_REQUEST['db_username']; - $db_password = $_REQUEST['db_password']; - $fp = @fsockopen($db_hostname, $db_port, $errno, $errstr, 30); - if ( !$fp ) { - $info->message .= "Connection Error: $errstr ($errno)"; - return $info; + public function getEngines () + { + $this->setResponseType( 'json' ); + $engines = array (); + if (function_exists( 'mysql_query' )) { + $engine = new stdclass(); + $engine->id = 'mysql'; + $engine->label = 'MySQL'; + $engines[] = $engine; + } + /** + * DISABLED TEMPORARELY + * if (function_exists('mssql_query')) { + * $engine = new stdclass(); + * $engine->id = 'mssql'; + * $engine->label = 'Microsoft SQL Server'; + * $engines[] = $engine; + * } + */ + return $engines; } - $db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname ; - $link = @mysql_connect($db_host, $db_username, $db_password); - if (!$link) { - $info->message .= "Connection Error: unable to connect to MySQL using provided credentials."; - return $info; - } - $res = @mysql_query("SELECT * FROM `information_schema`.`USER_PRIVILEGES` where (GRANTEE = \"'$db_username'@'$db_hostname'\" OR GRANTEE = \"'$db_username'@'%'\") and PRIVILEGE_TYPE = 'SUPER' ", $link); - $row = @mysql_fetch_array($res); - $hasSuper = is_array($row); - @mysql_free_result($res); - @mysql_close($link); - if (!$hasSuper) { - $info->message .= "Connection Error: User '$db_username' can't create databases and Users
Please provide an user with SUPER privilege."; - return $info; - } - $info->message .= "Succesfully connected to MySQL Server"; - $info->result = true; - return $info; - } + public function checkDatabases () + { + $this->setResponseType( 'json' ); + $info = new stdclass(); - private function testMSSQLconnection() - { - $info->result = false; - $info->message = ''; - if ( !function_exists("mssql_connect") ) { - $info->message = 'php-mssql is Not Installed'; - return $info; + if ($_REQUEST['db_engine'] == 'mysql') { + $link = @mysql_connect( $_REQUEST['db_hostname'], $_REQUEST['db_username'], $_REQUEST['db_password'] ); + $dataset = @mysql_query( "show databases like '" . $_REQUEST['wfDatabase'] . "'", $link ); + $info->wfDatabaseExists = (@mysql_num_rows( $dataset ) > 0); + $dataset = @mysql_query( "show databases like '" . $_REQUEST['rbDatabase'] . "'", $link ); + $info->rbDatabaseExists = (@mysql_num_rows( $dataset ) > 0); + $dataset = @mysql_query( "show databases like '" . $_REQUEST['rpDatabase'] . "'", $link ); + $info->rpDatabaseExists = (@mysql_num_rows( $dataset ) > 0); + } else { + $link = @mssql_connect( $_REQUEST['db_hostname'], $_REQUEST['db_username'], $_REQUEST['db_password'] ); + $dataset = @mssql_query( "select * from sys.databases where name = '" . $_REQUEST['wfDatabase'] . "'", $link ); + $info->wfDatabaseExists = (@mssql_num_rows( $dataset ) > 0); + $dataset = @mssql_query( "select * from sys.databases where name = '" . $_REQUEST['rbDatabase'] . "'", $link ); + $info->rbDatabaseExists = (@mssql_num_rows( $dataset ) > 0); + $dataset = @mssql_query( "select * from sys.databases where name = '" . $_REQUEST['rpDatabase'] . "'", $link ); + $info->rpDatabaseExists = (@mssql_num_rows( $dataset ) > 0); + } + + $info->errMessage = 'Database already exists, check "Delete Databases if exists" to overwrite the exiting databases.'; + + return $info; } - $db_hostname = $_REQUEST['db_hostname']; - $db_port = $_REQUEST['db_port']; - $db_username = $_REQUEST['db_username']; - $db_password = $_REQUEST['db_password']; + /** + * Privates functions section, non callable by http request + */ - $fp = @fsockopen($db_hostname, $db_port, $errno, $errstr, 30); - if ( !$fp ) { - $info->message .= "Connection Error: $errstr ($errno)"; - return $info; + private function testMySQLconnection () + { + $info->result = false; + $info->message = ''; + if (! function_exists( "mysql_connect" )) { + $info->message = 'php-mysql is Not Installed'; + return $info; + } + $db_hostname = $_REQUEST['db_hostname']; + $db_port = $_REQUEST['db_port']; + $db_username = $_REQUEST['db_username']; + $db_password = $_REQUEST['db_password']; + $fp = @fsockopen( $db_hostname, $db_port, $errno, $errstr, 30 ); + if (! $fp) { + $info->message .= "Connection Error: $errstr ($errno)"; + return $info; + } + + $db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname; + $link = @mysql_connect( $db_host, $db_username, $db_password ); + if (! $link) { + $info->message .= "Connection Error: unable to connect to MySQL using provided credentials."; + return $info; + } + $res = @mysql_query( "SELECT * FROM `information_schema`.`USER_PRIVILEGES` where (GRANTEE = \"'$db_username'@'$db_hostname'\" OR GRANTEE = \"'$db_username'@'%'\") and PRIVILEGE_TYPE = 'SUPER' ", $link ); + $row = @mysql_fetch_array( $res ); + $hasSuper = is_array( $row ); + @mysql_free_result( $res ); + @mysql_close( $link ); + if (! $hasSuper) { + $info->message .= "Connection Error: User '$db_username' can't create databases and Users
Please provide an user with SUPER privilege."; + return $info; + } + $info->message .= "Succesfully connected to MySQL Server"; + $info->result = true; + return $info; } - $db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname ; - $link = @mssql_connect($db_host, $db_username, $db_password); - if (!$link) { - $info->message .= "Connection Error: unable to connect to MSSQL using provided credentials."; - return $info; + private function testMSSQLconnection () + { + $info->result = false; + $info->message = ''; + if (! function_exists( "mssql_connect" )) { + $info->message = 'php-mssql is Not Installed'; + return $info; + } + + $db_hostname = $_REQUEST['db_hostname']; + $db_port = $_REQUEST['db_port']; + $db_username = $_REQUEST['db_username']; + $db_password = $_REQUEST['db_password']; + + $fp = @fsockopen( $db_hostname, $db_port, $errno, $errstr, 30 ); + if (! $fp) { + $info->message .= "Connection Error: $errstr ($errno)"; + return $info; + } + + $db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname; + $link = @mssql_connect( $db_host, $db_username, $db_password ); + if (! $link) { + $info->message .= "Connection Error: unable to connect to MSSQL using provided credentials."; + return $info; + } + + //checking if user has the dbcreator role + $hasDbCreator = false; + $hasSecurityAdmin = false; + $hasSysAdmin = false; + + $res = @mssql_query( "EXEC sp_helpsrvrolemember 'dbcreator' ", $link ); + $row = mssql_fetch_array( $res ); + while (is_array( $row )) { + if ($row['MemberName'] == $db_username) { + $hasDbCreator = true; + } + $row = mssql_fetch_array( $res ); + } + mssql_free_result( $res ); + + $res = @mssql_query( "EXEC sp_helpsrvrolemember 'sysadmin' ", $link ); + $row = mssql_fetch_array( $res ); + while (is_array( $row )) { + if ($row['MemberName'] == $db_username) { + $hasSysAdmin = true; + } + $row = mssql_fetch_array( $res ); + } + mssql_free_result( $res ); + + $res = @mssql_query( "EXEC sp_helpsrvrolemember 'SecurityAdmin' ", $link ); + $row = mssql_fetch_array( $res ); + while (is_array( $row )) { + if ($row['MemberName'] == $db_username) { + $hasSecurityAdmin = true; + } + $row = mssql_fetch_array( $res ); + } + mssql_free_result( $res ); + + if (! ($hasSysAdmin || ($hasSecurityAdmin && $hasDbCreator))) { + $info->message .= "Connection Error: User '$db_username' can't create databases and Users
Please provide an user with sysadmin role or dbcreator and securityadmin roles."; + return $info; + } + + $info->message .= "Succesfully connected to MSSQL Server"; + $info->result = true; + return $info; } +} - //checking if user has the dbcreator role - $hasDbCreator = false; - $hasSecurityAdmin = false; - $hasSysAdmin = false; - - $res = @mssql_query( "EXEC sp_helpsrvrolemember 'dbcreator' ", $link ); - $row = mssql_fetch_array($res); - while ( is_array( $row ) ) { - if ( $row['MemberName'] == $db_username ) $hasDbCreator = true; - $row = mssql_fetch_array($res); - } - mssql_free_result($res); - - $res = @mssql_query( "EXEC sp_helpsrvrolemember 'sysadmin' ", $link ); - $row = mssql_fetch_array($res); - while ( is_array( $row ) ) { - if ( $row['MemberName'] == $db_username ) $hasSysAdmin = true; - $row = mssql_fetch_array($res); - } - mssql_free_result($res); - - $res = @mssql_query( "EXEC sp_helpsrvrolemember 'SecurityAdmin' ", $link ); - $row = mssql_fetch_array($res); - while ( is_array( $row ) ) { - if ( $row['MemberName'] == $db_username ) $hasSecurityAdmin = true; - $row = mssql_fetch_array($res); - } - mssql_free_result($res); - - if ( ! ( $hasSysAdmin || ( $hasSecurityAdmin && $hasDbCreator) ) ) { - $info->message .= "Connection Error: User '$db_username' can't create databases and Users
Please provide an user with sysadmin role or dbcreator and securityadmin roles."; - return $info; - } - - $info->message .= "Succesfully connected to MSSQL Server"; - $info->result = true; - return $info; - } -} \ No newline at end of file diff --git a/workflow/engine/controllers/main.php b/workflow/engine/controllers/main.php index df16f2fe5..a5c0b076e 100644 --- a/workflow/engine/controllers/main.php +++ b/workflow/engine/controllers/main.php @@ -1,7 +1,9 @@ */ @@ -10,89 +12,87 @@ class Main extends Controller private $memcache; private $conf; - public function __construct() + public function __construct () { - G::LoadClass('memcached'); - $this->memcache = & PMmemcached::getSingleton(defined('SYS_SYS') ? SYS_SYS : ''); + G::LoadClass( 'memcached' ); + $this->memcache = & PMmemcached::getSingleton( defined( 'SYS_SYS' ) ? SYS_SYS : '' ); - define('ERROR_EXCEPTION' , 1); - define('INFO_EXCEPTION' , 3); - define('WARNING_EXCEPTION', 2); + define( 'ERROR_EXCEPTION', 1 ); + define( 'INFO_EXCEPTION', 3 ); + define( 'WARNING_EXCEPTION', 2 ); - //$this->setDebug(true); + //$this->setDebug(true); } - function index($httpData) + function index ($httpData) { global $RBAC; - $RBAC->requirePermissions('PM_LOGIN'); - $meta = new stdClass; - $showSystemInfo = $RBAC->userCanAccess('PM_SETUP') == 1; + $RBAC->requirePermissions( 'PM_LOGIN' ); + $meta = new stdClass(); + $showSystemInfo = $RBAC->userCanAccess( 'PM_SETUP' ) == 1; // setting variables for template - $this->setVar('logo_company', $this->getCompanyLogo()); - $this->setVar('userfullname', htmlentities($this->getUserFullName(), ENT_QUOTES, 'UTF-8') ); - $this->setVar('user', isset($_SESSION['USR_USERNAME']) ? $_SESSION['USR_USERNAME'] : ''); - $this->setVar('pipe', isset($_SESSION['USR_USERNAME']) ? ' | ' : ''); - $this->setVar('rolename', $this->getUserRole()); - $this->setVar('logout', G::LoadTranslation('ID_LOGOUT')); - $this->setVar('workspace', defined('SYS_SYS')? ucfirst(SYS_SYS): ''); - $this->setVar('user_avatar', 'users/users_ViewPhotoGrid?pUID=' . $_SESSION['USER_LOGGED'].'&h=' . rand()); - $this->setVar('udate', G::getformatedDate(date('Y-m-d'), 'M d, yyyy', SYS_LANG)); + $this->setVar( 'logo_company', $this->getCompanyLogo() ); + $this->setVar( 'userfullname', htmlentities( $this->getUserFullName(), ENT_QUOTES, 'UTF-8' ) ); + $this->setVar( 'user', isset( $_SESSION['USR_USERNAME'] ) ? $_SESSION['USR_USERNAME'] : '' ); + $this->setVar( 'pipe', isset( $_SESSION['USR_USERNAME'] ) ? ' | ' : '' ); + $this->setVar( 'rolename', $this->getUserRole() ); + $this->setVar( 'logout', G::LoadTranslation( 'ID_LOGOUT' ) ); + $this->setVar( 'workspace', defined( 'SYS_SYS' ) ? ucfirst( SYS_SYS ) : '' ); + $this->setVar( 'user_avatar', 'users/users_ViewPhotoGrid?pUID=' . $_SESSION['USER_LOGGED'] . '&h=' . rand() ); + $this->setVar( 'udate', G::getformatedDate( date( 'Y-m-d' ), 'M d, yyyy', SYS_LANG ) ); // license notification $expireInLabel = ''; - if (class_exists('pmLicenseManager')) { + if (class_exists( 'pmLicenseManager' )) { $pmLicenseManager = &pmLicenseManager::getSingleton(); - $expireIn = $pmLicenseManager->getExpireIn(); - $expireInLabel = $pmLicenseManager->getExpireInLabel(); + $expireIn = $pmLicenseManager->getExpireIn(); + $expireInLabel = $pmLicenseManager->getExpireInLabel(); } - $this->setVar('licenseNotification', $expireInLabel); + $this->setVar( 'licenseNotification', $expireInLabel ); // setting variables on javascript env. - $this->setJSVar('meta', array('menu'=>$this->getMenu())); + $this->setJSVar( 'meta', array ('menu' => $this->getMenu() + ) ); $activeTab = 0; - if (isset($_SESSION['_defaultUserLocation'])) { - $activeTab = $this->resolveUrlToTabIndex($_SESSION['_defaultUserLocation']); + if (isset( $_SESSION['_defaultUserLocation'] )) { + $activeTab = $this->resolveUrlToTabIndex( $_SESSION['_defaultUserLocation'] ); } - if (isset($_GET['st'])) { - $activeTab = $this->getActiveTab($_GET['st']); - unset($_GET['st']); + if (isset( $_GET['st'] )) { + $activeTab = $this->getActiveTab( $_GET['st'] ); + unset( $_GET['st'] ); } - $this->setJSVar('activeTab', $activeTab); - $this->setJSVar('urlAddGetParams', $this->getUrlGetParams()); - $this->setJSVar('showSystemInfo', $showSystemInfo); + $this->setJSVar( 'activeTab', $activeTab ); + $this->setJSVar( 'urlAddGetParams', $this->getUrlGetParams() ); + $this->setJSVar( 'showSystemInfo', $showSystemInfo ); - $switchInterface = isset($_SESSION['user_experience']) && $_SESSION['user_experience'] == 'SWITCHABLE'; + $switchInterface = isset( $_SESSION['user_experience'] ) && $_SESSION['user_experience'] == 'SWITCHABLE'; if (($flyNotify = $this->getFlyNotify()) !== false) { - $this->setJSVar('flyNotify', $flyNotify); + $this->setJSVar( 'flyNotify', $flyNotify ); } - $this->setJSVar('switchInterface', $switchInterface); + $this->setJSVar( 'switchInterface', $switchInterface ); - $this->includeExtJSLib('ux/ux.menu'); - $this->includeExtJS('main/index'); - $this->setLayout('pm-modern'); - $this->afterLoad($httpData); + $this->includeExtJSLib( 'ux/ux.menu' ); + $this->includeExtJS( 'main/index' ); + $this->setLayout( 'pm-modern' ); + $this->afterLoad( $httpData ); $this->render(); } - function getSystemInfo() + function getSystemInfo () { - $this->setResponseType('json'); + $this->setResponseType( 'json' ); $infoList = $this->_getSystemInfo(); - $data = array(); + $data = array (); foreach ($infoList as $row) { - $data[] = array( - 'label' => $row[0], - 'value' => $row[1], - 'section' => $row[2], + $data[] = array ('label' => $row[0],'value' => $row[1],'section' => $row[2] ); } return $data; @@ -101,65 +101,64 @@ class Main extends Controller /** * Login */ - public function login() + public function login () { require_once 'classes/model/LoginLog.php'; - G::LoadClass('system'); - G::loadClass('configuration'); - $this->conf = new Configurations; + G::LoadClass( 'system' ); + G::loadClass( 'configuration' ); + $this->conf = new Configurations(); // getting posibles errors passed by GET method $this->getInUrlError(); - if (!isset ($_SESSION ['G_MESSAGE'])) { + if (! isset( $_SESSION['G_MESSAGE'] )) { $_SESSION['G_MESSAGE'] = ''; } - if (!isset ($_SESSION ['G_MESSAGE_TYPE'])) { + if (! isset( $_SESSION['G_MESSAGE_TYPE'] )) { $_SESSION['G_MESSAGE_TYPE'] = ''; } $msg = $_SESSION['G_MESSAGE']; $msgType = $_SESSION['G_MESSAGE_TYPE']; - if (! isset($_SESSION['FAILED_LOGINS'])) { + if (! isset( $_SESSION['FAILED_LOGINS'] )) { $_SESSION['FAILED_LOGINS'] = 0; } - $sFailedLogins = $_SESSION ['FAILED_LOGINS']; + $sFailedLogins = $_SESSION['FAILED_LOGINS']; - if (isset ($_SESSION ['USER_LOGGED'])) { + if (isset( $_SESSION['USER_LOGGED'] )) { //close the session, if the current session_id was used in PM. - $oCriteria = new Criteria ('workflow'); - $oCriteria->add (LoginLogPeer::LOG_SID, session_id ()); - $oCriteria->add (LoginLogPeer::USR_UID, isset ($_SESSION ['USER_LOGGED']) ? - $_SESSION ['USER_LOGGED'] : '-'); - $oCriteria->add (LoginLogPeer::LOG_STATUS, 'ACTIVE'); - $oCriteria->add (LoginLogPeer::LOG_END_DATE, null, Criteria::ISNULL); - $oDataset = LoginLogPeer::doSelectRS ($oCriteria); - $oDataset->setFetchmode (ResultSet::FETCHMODE_ASSOC); - $oDataset->next (); - $aRow = $oDataset->getRow (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( LoginLogPeer::LOG_SID, session_id() ); + $oCriteria->add( LoginLogPeer::USR_UID, isset( $_SESSION['USER_LOGGED'] ) ? $_SESSION['USER_LOGGED'] : '-' ); + $oCriteria->add( LoginLogPeer::LOG_STATUS, 'ACTIVE' ); + $oCriteria->add( LoginLogPeer::LOG_END_DATE, null, Criteria::ISNULL ); + $oDataset = LoginLogPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aRow = $oDataset->getRow(); if ($aRow) { - if ($aRow ['LOG_STATUS'] != 'CLOSED' && $aRow ['LOG_END_DATE'] == null) { - $weblog = new LoginLog (); - $aLog ['LOG_UID'] = $aRow ['LOG_UID']; - $aLog ['LOG_STATUS'] = 'CLOSED'; - $aLog ['LOG_IP'] = $aRow ['LOG_IP']; - $aLog ['LOG_SID'] = session_id (); - $aLog ['LOG_INIT_DATE'] = $aRow ['LOG_INIT_DATE']; - $aLog ['LOG_END_DATE'] = date ('Y-m-d H:i:s'); - $aLog ['LOG_CLIENT_HOSTNAME'] = $aRow ['LOG_CLIENT_HOSTNAME']; - $aLog ['USR_UID'] = $aRow ['USR_UID']; - $weblog->update ($aLog); + if ($aRow['LOG_STATUS'] != 'CLOSED' && $aRow['LOG_END_DATE'] == null) { + $weblog = new LoginLog(); + $aLog['LOG_UID'] = $aRow['LOG_UID']; + $aLog['LOG_STATUS'] = 'CLOSED'; + $aLog['LOG_IP'] = $aRow['LOG_IP']; + $aLog['LOG_SID'] = session_id(); + $aLog['LOG_INIT_DATE'] = $aRow['LOG_INIT_DATE']; + $aLog['LOG_END_DATE'] = date( 'Y-m-d H:i:s' ); + $aLog['LOG_CLIENT_HOSTNAME'] = $aRow['LOG_CLIENT_HOSTNAME']; + $aLog['USR_UID'] = $aRow['USR_UID']; + $weblog->update( $aLog ); } } //remove memcached session - $this->memcache->delete('rbacSession' . session_id()) ; + $this->memcache->delete( 'rbacSession' . session_id() ); } else { // Execute SSO trigger - $pluginRegistry =& PMPluginRegistry::getSingleton(); - if (defined('PM_SINGLE_SIGN_ON')) { - if ($pluginRegistry->existsTrigger(PM_SINGLE_SIGN_ON)) { - if ($pluginRegistry->executeTriggers(PM_SINGLE_SIGN_ON, null)) { + $pluginRegistry = & PMPluginRegistry::getSingleton(); + if (defined( 'PM_SINGLE_SIGN_ON' )) { + if ($pluginRegistry->existsTrigger( PM_SINGLE_SIGN_ON )) { + if ($pluginRegistry->executeTriggers( PM_SINGLE_SIGN_ON, null )) { // Start new session @session_destroy(); session_start(); @@ -168,7 +167,7 @@ class Main extends Controller $result = $this->authentication(); if ($result->success) { // Redirect to landing page for the user - G::header('Location: ' . $result->url); + G::header( 'Location: ' . $result->url ); die(); } } @@ -177,110 +176,107 @@ class Main extends Controller } //end log - //start new session - @session_destroy (); - session_start (); - session_regenerate_id (); - if (strlen ($msg) > 0) { - $_SESSION ['G_MESSAGE'] = $msg; + //start new session + @session_destroy(); + session_start(); + session_regenerate_id(); + + if (strlen( $msg ) > 0) { + $_SESSION['G_MESSAGE'] = $msg; } - if (strlen ($msgType) > 0) { - $_SESSION ['G_MESSAGE_TYPE'] = $msgType; + if (strlen( $msgType ) > 0) { + $_SESSION['G_MESSAGE_TYPE'] = $msgType; } - $_SESSION ['FAILED_LOGINS'] = $sFailedLogins; + $_SESSION['FAILED_LOGINS'] = $sFailedLogins; $availableLangArray = $this->getLanguagesList(); - G::LoadClass("serverConfiguration"); + G::LoadClass( "serverConfiguration" ); $sflag = 0; - if (($nextBeatDate = $this->memcache->get('nextBeatDate')) === false) { + if (($nextBeatDate = $this->memcache->get( 'nextBeatDate' )) === false) { //get the serverconf singleton, and check if we can send the heartbeat - $oServerConf = & serverConf::getSingleton (); - $sflag = $oServerConf->getHeartbeatProperty('HB_OPTION','HEART_BEAT_CONF'); - $sflag = (trim($sflag)!='')? $sflag : '1'; + $oServerConf = & serverConf::getSingleton(); + $sflag = $oServerConf->getHeartbeatProperty( 'HB_OPTION', 'HEART_BEAT_CONF' ); + $sflag = (trim( $sflag ) != '') ? $sflag : '1'; //get date of next beat - $nextBeatDate = $oServerConf->getHeartbeatProperty('HB_NEXT_BEAT_DATE','HEART_BEAT_CONF'); - $this->memcache->set('nextBeatDate', $nextBeatDate, 1*3600); + $nextBeatDate = $oServerConf->getHeartbeatProperty( 'HB_NEXT_BEAT_DATE', 'HEART_BEAT_CONF' ); + $this->memcache->set( 'nextBeatDate', $nextBeatDate, 1 * 3600 ); } else { $sflag = '1'; } - if (($sflag == '1') && ((strtotime("now") > $nextBeatDate) || is_null($nextBeatDate))) { + if (($sflag == '1') && ((strtotime( "now" ) > $nextBeatDate) || is_null( $nextBeatDate ))) { //To do: we need to change to ExtJs - $this->setJSVar('flagHeartBeat', 1); + $this->setJSVar( 'flagHeartBeat', 1 ); } else { - $this->setJSVar('flagHeartBeat', 0); + $this->setJSVar( 'flagHeartBeat', 0 ); } - if (($flagGettingStarted = $this->memcache->get('flagGettingStarted')) === false) { + if (($flagGettingStarted = $this->memcache->get( 'flagGettingStarted' )) === false) { require_once 'classes/model/Configuration.php'; - $oConfiguration = new Configuration (); - $oCriteria = new Criteria ('workflow'); - $oCriteria->add (ConfigurationPeer::CFG_UID, 'getStarted'); - $oCriteria->add (ConfigurationPeer::OBJ_UID, ''); - $oCriteria->add (ConfigurationPeer::CFG_VALUE, '1'); - $oCriteria->add (ConfigurationPeer::PRO_UID, ''); - $oCriteria->add (ConfigurationPeer::USR_UID, ''); - $oCriteria->add (ConfigurationPeer::APP_UID, ''); - $flagGettingStarted = ConfigurationPeer::doCount ($oCriteria); - $this->memcache->set('flagGettingStarted', $flagGettingStarted, 8*3600) ; + $oConfiguration = new Configuration(); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ConfigurationPeer::CFG_UID, 'getStarted' ); + $oCriteria->add( ConfigurationPeer::OBJ_UID, '' ); + $oCriteria->add( ConfigurationPeer::CFG_VALUE, '1' ); + $oCriteria->add( ConfigurationPeer::PRO_UID, '' ); + $oCriteria->add( ConfigurationPeer::USR_UID, '' ); + $oCriteria->add( ConfigurationPeer::APP_UID, '' ); + $flagGettingStarted = ConfigurationPeer::doCount( $oCriteria ); + $this->memcache->set( 'flagGettingStarted', $flagGettingStarted, 8 * 3600 ); } - $this->setJSVar('flagGettingStarted', ($flagGettingStarted == 0)); + $this->setJSVar( 'flagGettingStarted', ($flagGettingStarted == 0) ); - G::loadClass('configuration'); - $oConf = new Configurations; - $oConf->loadConfig($obj, 'ENVIRONMENT_SETTINGS',''); + G::loadClass( 'configuration' ); + $oConf = new Configurations(); + $oConf->loadConfig( $obj, 'ENVIRONMENT_SETTINGS', '' ); - $flagForgotPassword = isset($oConf->aConfig['login_enableForgotPassword'])? - $oConf->aConfig['login_enableForgotPassword']: 'off'; + $flagForgotPassword = isset( $oConf->aConfig['login_enableForgotPassword'] ) ? $oConf->aConfig['login_enableForgotPassword'] : 'off'; - $this->includeExtJSLib('ux/virtualkeyboard'); - $this->includeExtJS('main/login'); - $this->setView('main/login'); + $this->includeExtJSLib( 'ux/virtualkeyboard' ); + $this->includeExtJS( 'main/login' ); + $this->setView( 'main/login' ); - $oConf->loadConfig($obj, 'ENVIRONMENT_SETTINGS',''); + $oConf->loadConfig( $obj, 'ENVIRONMENT_SETTINGS', '' ); - $forgotPasswd = isset($oConf->aConfig['login_enableForgotPassword'])? - $oConf->aConfig['login_enableForgotPassword']: false; - $virtualKeyboad = isset($oConf->aConfig['login_enableVirtualKeyboard'])? - $oConf->aConfig['login_enableVirtualKeyboard']: false; - $defaultLanguaje = isset($oConf->aConfig['login_defaultLanguage'])? - $oConf->aConfig['login_defaultLanguage']: 'en'; + $forgotPasswd = isset( $oConf->aConfig['login_enableForgotPassword'] ) ? $oConf->aConfig['login_enableForgotPassword'] : false; + $virtualKeyboad = isset( $oConf->aConfig['login_enableVirtualKeyboard'] ) ? $oConf->aConfig['login_enableVirtualKeyboard'] : false; + $defaultLanguaje = isset( $oConf->aConfig['login_defaultLanguage'] ) ? $oConf->aConfig['login_defaultLanguage'] : 'en'; - $this->setJSVar('forgotPasswd', $forgotPasswd); - $this->setJSVar('virtualKeyboad', $virtualKeyboad); + $this->setJSVar( 'forgotPasswd', $forgotPasswd ); + $this->setJSVar( 'virtualKeyboad', $virtualKeyboad ); - $this->setJSVar('languages', $availableLangArray); - $this->setJSVar('defaultLang', $defaultLanguaje); + $this->setJSVar( 'languages', $availableLangArray ); + $this->setJSVar( 'defaultLang', $defaultLanguaje ); //binding G::SendTemporalMessage() to Ext.msgBoxSlider.msgTopCenter() if (($flyNotify = $this->getFlyNotify()) !== false) { - $this->setJSVar('flyNotify', $flyNotify); + $this->setJSVar( 'flyNotify', $flyNotify ); } //binding G::SendTemporalMessage() to Ext.msgBoxSlider.msgTopCenter() - if (isset($_GET['u'])) { - $this->setJSVar('urlRequested', urldecode($_GET['u'])); + if (isset( $_GET['u'] )) { + $this->setJSVar( 'urlRequested', urldecode( $_GET['u'] ) ); } - $this->setVar('logo_company', $this->getCompanyLogo()); - $this->setVar('pmos_version', System::getVersion()); + $this->setVar( 'logo_company', $this->getCompanyLogo() ); + $this->setVar( 'pmos_version', System::getVersion() ); - $footerText = 'Copyright © 2003-' . date('Y') . ' Colosa, Inc. All rights reserved.'; + $footerText = 'Copyright © 2003-' . date( 'Y' ) . ' Colosa, Inc. All rights reserved.'; $adviseText = 'Supplied free of charge with no support, certification, warranty, maintenance nor indemnity by Colosa and its Certified Partners. '; - $this->setVar('footer_text', $footerText); - $this->setVar('advise_text', $adviseText); - $loginScript = $this->getHeadPublisher()->getExtJsLibraries(); + $this->setVar( 'footer_text', $footerText ); + $this->setVar( 'advise_text', $adviseText ); + $loginScript = $this->getHeadPublisher()->getExtJsLibraries(); $loginScript .= $this->getHeadPublisher()->getExtJsScripts(); - $this->setVar('login_script', $loginScript); - $this->setVar('login_vars', $this->getHeadPublisher()->getExtJsVariablesScript()); + $this->setVar( 'login_script', $loginScript ); + $this->setVar( 'login_vars', $this->getHeadPublisher()->getExtJsVariablesScript() ); - $this->setLayout('pm-modern-login'); + $this->setLayout( 'pm-modern-login' ); $this->render(); } @@ -288,122 +284,122 @@ class Main extends Controller /** * SysLogin */ - public function sysLogin() + public function sysLogin () { require_once ("propel/Propel.php"); require_once ("creole/Creole.php"); - G::LoadClass('system'); - G::LoadThirdParty ("pake", "pakeColor.class"); - Propel::init (PATH_CORE . "config/databases.php"); - Creole::registerDriver ('dbarray', 'creole.contrib.DBArrayConnection'); + G::LoadClass( 'system' ); + G::LoadThirdParty( "pake", "pakeColor.class" ); + Propel::init( PATH_CORE . "config/databases.php" ); + Creole::registerDriver( 'dbarray', 'creole.contrib.DBArrayConnection' ); // getting posibles errors passed by GET method $this->getInUrlError(); $availableWorkspace = $this->getWorkspacesAvailable(); - $availableWorkspaceList = array(); + $availableWorkspaceList = array (); foreach ($availableWorkspace as $ws) { - $availableWorkspaceList[] = array($ws, $ws); + $availableWorkspaceList[] = array ($ws,$ws + ); } - $aField ['LOGIN_VERIFY_MSG'] = G::loadTranslation('LOGIN_VERIFY_MSG'); + $aField['LOGIN_VERIFY_MSG'] = G::loadTranslation( 'LOGIN_VERIFY_MSG' ); //Get Server Configuration - G::LoadClass ('serverConfiguration'); - $oServerConf = & serverConf::getSingleton (); + G::LoadClass( 'serverConfiguration' ); + $oServerConf = & serverConf::getSingleton(); $availableLangArray = $this->getLanguagesList(); - $this->includeExtJSLib('ux/virtualkeyboard'); - $this->setJSVar('sysLang', SYS_LANG); - $this->includeExtJS('main/sysLogin'); + $this->includeExtJSLib( 'ux/virtualkeyboard' ); + $this->setJSVar( 'sysLang', SYS_LANG ); + $this->includeExtJS( 'main/sysLogin' ); - $this->setVar('logo_company', $this->getCompanyLogo()); - $this->setVar('pmos_version', System::getVersion()); + $this->setVar( 'logo_company', $this->getCompanyLogo() ); + $this->setVar( 'pmos_version', System::getVersion() ); - $footerText = 'Copyright © 2003-' . date('Y') . ' Colosa, Inc. All rights reserved.'; + $footerText = 'Copyright © 2003-' . date( 'Y' ) . ' Colosa, Inc. All rights reserved.'; $adviseText = 'Supplied free of charge with no support, certification, warranty, maintenance nor indemnity by Colosa and its Certified Partners. '; - $this->setVar('footer_text', $footerText); - $this->setVar('advise_text', $adviseText); + $this->setVar( 'footer_text', $footerText ); + $this->setVar( 'advise_text', $adviseText ); //binding G::SendTemporalMessage() to Ext.msgBoxSlider.msgTopCenter() if (($flyNotify = $this->getFlyNotify()) !== false) { - $this->setJSVar('flyNotify', $flyNotify); + $this->setJSVar( 'flyNotify', $flyNotify ); } - $this->setJSVar('languages', $availableLangArray); - $this->setJSVar('workspaces', $availableWorkspaceList); - $this->setJSVar('wsPrivate', $oServerConf->getProperty('LOGIN_NO_WS')); + $this->setJSVar( 'languages', $availableLangArray ); + $this->setJSVar( 'workspaces', $availableWorkspaceList ); + $this->setJSVar( 'wsPrivate', $oServerConf->getProperty( 'LOGIN_NO_WS' ) ); - $this->setJSVar('defaultLang', 'en'); - $this->setJSVar('defaultWS', ''); + $this->setJSVar( 'defaultLang', 'en' ); + $this->setJSVar( 'defaultWS', '' ); - $loginScript = $this->getHeadPublisher()->getExtJsLibraries(); + $loginScript = $this->getHeadPublisher()->getExtJsLibraries(); $loginScript .= $this->getHeadPublisher()->getExtJsScripts(); - $this->setVar('login_script', $loginScript); - $this->setVar('login_vars', $this->getHeadPublisher()->getExtJsVariablesScript()); + $this->setVar( 'login_script', $loginScript ); + $this->setVar( 'login_vars', $this->getHeadPublisher()->getExtJsVariablesScript() ); - $this->setLayout('pm-modern-login'); + $this->setLayout( 'pm-modern-login' ); $this->render(); } - public function forgotPassword($httpData) + public function forgotPassword ($httpData) { - $this->setResponseType('json'); + $this->setResponseType( 'json' ); global $RBAC; - require_once PATH_RBAC."model/RbacUsers.php"; + require_once PATH_RBAC . "model/RbacUsers.php"; require_once 'classes/model/Users.php'; - G::LoadClass("system"); + G::LoadClass( "system" ); $rbacUser = new RbacUsers(); $user = new Users(); try { - $userData = $rbacUser->getByUsername($httpData->username); + $userData = $rbacUser->getByUsername( $httpData->username ); - if (!$userData) { - $msg = G::LoadTranslation('ID_USER') . ' ' . $httpData->username . ' '. - G::LoadTranslation('ID_IS_NOT_REGISTERED'); - throw new Exception($msg); + if (! $userData) { + $msg = G::LoadTranslation( 'ID_USER' ) . ' ' . $httpData->username . ' ' . G::LoadTranslation( 'ID_IS_NOT_REGISTERED' ); + throw new Exception( $msg ); } - if (trim($userData['USR_EMAIL']) != trim($httpData->email)) { - $msg = G::LoadTranslation('ID_EMAIL_DOES_NOT_MATCH_FOR_USER') .' '. $httpData->username . ''; - throw new Exception($msg); + if (trim( $userData['USR_EMAIL'] ) != trim( $httpData->email )) { + $msg = G::LoadTranslation( 'ID_EMAIL_DOES_NOT_MATCH_FOR_USER' ) . ' ' . $httpData->username . ''; + throw new Exception( $msg ); } $newPass = G::generate_password(); - $aData['USR_UID'] = $userData['USR_UID']; - $aData['USR_PASSWORD'] = md5($newPass); + $aData['USR_UID'] = $userData['USR_UID']; + $aData['USR_PASSWORD'] = md5( $newPass ); - $rbacUser->update($aData); - $user->update($aData); + $rbacUser->update( $aData ); + $user->update( $aData ); - $subject = G::loadTranslation('ID_PROCESSMAKER_FORGOT_PASSWORD_SERVICE'); + $subject = G::loadTranslation( 'ID_PROCESSMAKER_FORGOT_PASSWORD_SERVICE' ); - $template = new TemplatePower(PATH_TPL . 'main/forgotPassword.tpl'); + $template = new TemplatePower( PATH_TPL . 'main/forgotPassword.tpl' ); $template->prepare(); - $template->assign('server', $_SERVER['SERVER_NAME']); + $template->assign( 'server', $_SERVER['SERVER_NAME'] ); - $template->assign('serviceMsg', G::loadTranslation('ID_PROCESSMAKER_FORGOT_PASSWORD_SERVICE')); - $template->assign('content', G::loadTranslation('ID_PASSWORD_CHANGED_SUCCESSFULLY')); - $template->assign('passwd', $newPass); - $template->assign('poweredBy', G::loadTranslation('ID_PROCESSMAKER_SLOGAN1')); - $template->assign('versionLabel', G::loadTranslation('ID_VERSION')); - $template->assign('version', System::getVersion()); - $template->assign('visit', G::loadTranslation('ID_VISIT')); + $template->assign( 'serviceMsg', G::loadTranslation( 'ID_PROCESSMAKER_FORGOT_PASSWORD_SERVICE' ) ); + $template->assign( 'content', G::loadTranslation( 'ID_PASSWORD_CHANGED_SUCCESSFULLY' ) ); + $template->assign( 'passwd', $newPass ); + $template->assign( 'poweredBy', G::loadTranslation( 'ID_PROCESSMAKER_SLOGAN1' ) ); + $template->assign( 'versionLabel', G::loadTranslation( 'ID_VERSION' ) ); + $template->assign( 'version', System::getVersion() ); + $template->assign( 'visit', G::loadTranslation( 'ID_VISIT' ) ); - $template->assign('footer', ''); + $template->assign( 'footer', '' ); $body = $template->getOutputContent(); - G::sendMail('', 'ProcessMaker Service', $httpData->email, $subject, $body); + G::sendMail( '', 'ProcessMaker Service', $httpData->email, $subject, $body ); $result->success = true; - $result->message = G::LoadTranslation('ID_NEW_PASSWORD_SENT'); + $result->message = G::LoadTranslation( 'ID_NEW_PASSWORD_SENT' ); } catch (Exception $e) { $result->success = false; $result->message = $e->getMessage(); @@ -411,10 +407,12 @@ class Main extends Controller return $result; } - /** * - * Private Functions * - * **/ - private function getMenu() + /** + * * + * Private Functions * + * * + */ + private function getMenu () { global $G_MAIN_MENU; global $G_SUB_MENU; @@ -423,45 +421,45 @@ class Main extends Controller global $G_ID_MENU_SELECTED; global $G_ID_SUB_MENU_SELECTED; - $G_MAIN_MENU = 'processmaker'; - $G_SUB_MENU = 'process'; - $G_ID_MENU_SELECTED = 'BPMN'; + $G_MAIN_MENU = 'processmaker'; + $G_SUB_MENU = 'process'; + $G_ID_MENU_SELECTED = 'BPMN'; $oMenu = new Menu(); - $menus = $oMenu->generateArrayForTemplate($G_MAIN_MENU, 'SelectedMenu', 'mainMenu', $G_MENU_SELECTED, - $G_ID_MENU_SELECTED); + $menus = $oMenu->generateArrayForTemplate( $G_MAIN_MENU, 'SelectedMenu', 'mainMenu', $G_MENU_SELECTED, $G_ID_MENU_SELECTED ); foreach ($menus as $i => $menu) { - if (strpos($menu['target'], 'cases/main') !== false) { - $menus[$i]['target'] = str_replace('cases/main', 'cases/main_init', $menus[$i]['target']); + if (strpos( $menu['target'], 'cases/main' ) !== false) { + $menus[$i]['target'] = str_replace( 'cases/main', 'cases/main_init', $menus[$i]['target'] ); } - if (strpos($menu['target'], 'bpmn/main') !== false) { - $menus[$i]['target'] = str_replace('bpmn/main', 'bpmn/mainInit', $menus[$i]['target']); + if (strpos( $menu['target'], 'bpmn/main' ) !== false) { + $menus[$i]['target'] = str_replace( 'bpmn/main', 'bpmn/mainInit', $menus[$i]['target'] ); } - if (strpos($menu['target'], 'processes/main') !== false) { - $menus[$i]['target'] = str_replace('processes/main', 'processes/mainInit', $menus[$i]['target']); + if (strpos( $menu['target'], 'processes/main' ) !== false) { + $menus[$i]['target'] = str_replace( 'processes/main', 'processes/mainInit', $menus[$i]['target'] ); } - if (strpos($menu['target'], 'setup/main') !== false) { - $menus[$i]['target'] = str_replace('setup/main', 'setup/main_init', $menus[$i]['target']); + if (strpos( $menu['target'], 'setup/main' ) !== false) { + $menus[$i]['target'] = str_replace( 'setup/main', 'setup/main_init', $menus[$i]['target'] ); } - if (strpos($menu['target'], 'dashboard/main') !== false) { - $menus[$i]['target'] = str_replace('dashboard/main', 'dashboard', $menus[$i]['target']); + if (strpos( $menu['target'], 'dashboard/main' ) !== false) { + $menus[$i]['target'] = str_replace( 'dashboard/main', 'dashboard', $menus[$i]['target'] ); } - $menus[$i]['elementclass'] = preg_replace(array('/class=/', '/"/'), array('', ''), - $menus[$i]['elementclass']) ; + $menus[$i]['elementclass'] = preg_replace( array ('/class=/','/"/' + ), array ('','' + ), $menus[$i]['elementclass'] ); } return $menus; } - private function resolveUrlToTabIndex($url) + private function resolveUrlToTabIndex ($url) { - if (strpos($url, 'cases/main') !== false) { + if (strpos( $url, 'cases/main' ) !== false) { $activeTab = 0; - } elseif (strpos($url, 'processes/main') !== false) { + } elseif (strpos( $url, 'processes/main' ) !== false) { $activeTab = 1; - } elseif (strpos($url, 'dashboard/main') !== false) { + } elseif (strpos( $url, 'dashboard/main' ) !== false) { $activeTab = 2; - } elseif (strpos($url, 'setup/main') !== false) { + } elseif (strpos( $url, 'setup/main' ) !== false) { $activeTab = 3; } else { $activeTab = 0; @@ -470,99 +468,98 @@ class Main extends Controller return $activeTab; } - private function getCompanyLogo() + private function getCompanyLogo () { $sCompanyLogo = '/images/processmaker2.logo2.png'; - if (defined("SYS_SYS")) { - if (($aFotoSelect = $this->memcache->get('aFotoSelect')) === false) { - G::LoadClass('replacementLogo'); + if (defined( "SYS_SYS" )) { + if (($aFotoSelect = $this->memcache->get( 'aFotoSelect' )) === false) { + G::LoadClass( 'replacementLogo' ); $oLogoR = new replacementLogo(); - $aFotoSelect = $oLogoR->getNameLogo((isset($_SESSION['USER_LOGGED'])) ? - $_SESSION['USER_LOGGED'] : ''); - $this->memcache->set('aFotoSelect', $aFotoSelect, 1*3600); + $aFotoSelect = $oLogoR->getNameLogo( (isset( $_SESSION['USER_LOGGED'] )) ? $_SESSION['USER_LOGGED'] : '' ); + $this->memcache->set( 'aFotoSelect', $aFotoSelect, 1 * 3600 ); } - if (is_array ($aFotoSelect)) { - $sFotoSelect = trim($aFotoSelect['DEFAULT_LOGO_NAME']); - $sWspaceSelect = trim($aFotoSelect['WORKSPACE_LOGO_NAME']); + if (is_array( $aFotoSelect )) { + $sFotoSelect = trim( $aFotoSelect['DEFAULT_LOGO_NAME'] ); + $sWspaceSelect = trim( $aFotoSelect['WORKSPACE_LOGO_NAME'] ); } } - if (class_exists('PMPluginRegistry')) { + if (class_exists( 'PMPluginRegistry' )) { $oPluginRegistry = &PMPluginRegistry::getSingleton(); - $logoPlugin = $oPluginRegistry->getCompanyLogo($sCompanyLogo); + $logoPlugin = $oPluginRegistry->getCompanyLogo( $sCompanyLogo ); if ($logoPlugin != '/images/processmaker2.logo2.png') { $sCompanyLogo = $logoPlugin; - } elseif (isset($sFotoSelect) && $sFotoSelect!='' && !(strcmp($sWspaceSelect,SYS_SYS))) { - $sCompanyLogo = $oPluginRegistry->getCompanyLogo($sFotoSelect); - $sCompanyLogo = "/sys".SYS_SYS."/".SYS_LANG."/".SYS_SKIN."/adminProxy/showLogoFile?id=". - base64_encode($sCompanyLogo); + } elseif (isset( $sFotoSelect ) && $sFotoSelect != '' && ! (strcmp( $sWspaceSelect, SYS_SYS ))) { + $sCompanyLogo = $oPluginRegistry->getCompanyLogo( $sFotoSelect ); + $sCompanyLogo = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/adminProxy/showLogoFile?id=" . base64_encode( $sCompanyLogo ); } } return $sCompanyLogo; } - public function getLanguagesList() + public function getLanguagesList () { //translation - $Translations = G::getModel("Translation"); + $Translations = G::getModel( "Translation" ); $translationsTable = $Translations->getTranslationEnvironments(); - if (($languagesList = $this->memcache->get('languagesList')) === false) { + if (($languagesList = $this->memcache->get( 'languagesList' )) === false) { $languagesList = array (); foreach ($translationsTable as $locale) { $LANG_ID = $locale['LOCALE']; if ($locale['COUNTRY'] != '.') { - $LANG_NAME = $locale['LANGUAGE'] . ' (' . (ucwords(strtolower($locale['COUNTRY']))) . ')'; + $LANG_NAME = $locale['LANGUAGE'] . ' (' . (ucwords( strtolower( $locale['COUNTRY'] ) )) . ')'; } else { $LANG_NAME = $locale['LANGUAGE']; } - $languagesList [] = array($LANG_ID, $LANG_NAME); + $languagesList[] = array ($LANG_ID,$LANG_NAME + ); } - $this->memcache->set('languagesList', $languagesList, 1*3600); + $this->memcache->set( 'languagesList', $languagesList, 1 * 3600 ); } return $languagesList; } - private function getWorkspacesAvailable() + private function getWorkspacesAvailable () { - G::LoadClass ('serverConfiguration'); - $oServerConf = & serverConf::getSingleton (); + G::LoadClass( 'serverConfiguration' ); + $oServerConf = & serverConf::getSingleton(); $dir = PATH_DB; $filesArray = array (); - if (file_exists ($dir)) { - if ($handle = opendir ($dir)) { - while (false !== ($file = readdir ($handle))) { + if (file_exists( $dir )) { + if ($handle = opendir( $dir )) { + while (false !== ($file = readdir( $handle ))) { if (($file != ".") && ($file != "..")) { - if (file_exists (PATH_DB . $file . '/db.php')) { - if (! $oServerConf->isWSDisabled ($file)) { - $filesArray [] = $file; + if (file_exists( PATH_DB . $file . '/db.php' )) { + if (! $oServerConf->isWSDisabled( $file )) { + $filesArray[] = $file; } } } } - closedir ($handle); + closedir( $handle ); } } - sort ($filesArray, SORT_STRING); + sort( $filesArray, SORT_STRING ); return $filesArray; } - private function getUserRole() + private function getUserRole () { global $RBAC; - $rolCode = str_replace('_', ' ', $RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_CODE']); - $rolUid = $RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_UID']; + $rolCode = str_replace( '_', ' ', $RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_CODE'] ); + $rolUid = $RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_UID']; - $oCriteria1 = new Criteria('workflow'); - $oCriteria1->add(ContentPeer::CON_CATEGORY, 'ROL_NAME'); - $oCriteria1->add(ContentPeer::CON_ID, $rolUid); - $oCriteria1->add(ContentPeer::CON_LANG, SYS_LANG); - $oDataset1 = ContentPeer::doSelectRS($oCriteria1); - $oDataset1->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $oCriteria1 = new Criteria( 'workflow' ); + $oCriteria1->add( ContentPeer::CON_CATEGORY, 'ROL_NAME' ); + $oCriteria1->add( ContentPeer::CON_ID, $rolUid ); + $oCriteria1->add( ContentPeer::CON_LANG, SYS_LANG ); + $oDataset1 = ContentPeer::doSelectRS( $oCriteria1 ); + $oDataset1->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset1->next(); $aRow = $oDataset1->getRow(); $rolName = $aRow['CON_VALUE']; @@ -573,44 +570,44 @@ class Main extends Controller /** * binding G::SendTemporalMessage() to Javascript routine Ext.msgBoxSlider.msgTopCenter() */ - private function getFlyNotify() + private function getFlyNotify () { - if (!isset($_SESSION['G_MESSAGE'])) { + if (! isset( $_SESSION['G_MESSAGE'] )) { return false; } - $flyNotify['title'] = isset($_SESSION['G_MESSAGE_TITLE']) ? $_SESSION['G_MESSAGE_TITLE'] : ''; + $flyNotify['title'] = isset( $_SESSION['G_MESSAGE_TITLE'] ) ? $_SESSION['G_MESSAGE_TITLE'] : ''; $flyNotify['text'] = $_SESSION['G_MESSAGE']; - unset($_SESSION['G_MESSAGE']); - if (isset($_SESSION['G_MESSAGE_TYPE'])) { + unset( $_SESSION['G_MESSAGE'] ); + if (isset( $_SESSION['G_MESSAGE_TYPE'] )) { $flyNotify['type'] = $_SESSION['G_MESSAGE_TYPE']; - unset($_SESSION['G_MESSAGE_TYPE']); + unset( $_SESSION['G_MESSAGE_TYPE'] ); } else { $flyNotify['type'] = ''; } if ($flyNotify['title'] == '') { - switch($flyNotify['type']) { + switch ($flyNotify['type']) { case 'alert': case 'warning': case 'tmp-warning': - $flyNotify['title'] = G::loadTranslation('ID_WARNING'); + $flyNotify['title'] = G::loadTranslation( 'ID_WARNING' ); break; case 'error': case 'tmp-error': - $flyNotify['title'] = G::loadTranslation('ID_ERROR'); + $flyNotify['title'] = G::loadTranslation( 'ID_ERROR' ); break; case 'tmp-info': case 'info': - $flyNotify['title'] = G::loadTranslation('ID_INFO'); + $flyNotify['title'] = G::loadTranslation( 'ID_INFO' ); break; case 'success': case 'ok': - $flyNotify['title'] = G::loadTranslation('ID_SUCCESS'); + $flyNotify['title'] = G::loadTranslation( 'ID_SUCCESS' ); break; } - $flyNotify['title'] = strtoupper($flyNotify['title']); + $flyNotify['title'] = strtoupper( $flyNotify['title'] ); } //TODO make dinamic $flyNotify['time'] = 5; @@ -619,22 +616,18 @@ class Main extends Controller return $this->flyNotify; } - private function setFlyNotify($type, $title, $text, $time=5) + private function setFlyNotify ($type, $title, $text, $time = 5) { - $this->flyNotify = array( - 'type' => $type, - 'title' => $title, - 'text' => $text, - 'time' => $time + $this->flyNotify = array ('type' => $type,'title' => $title,'text' => $text,'time' => $time ); - $_SESSION ['G_MESSAGE'] = $text; - $_SESSION ['G_MESSAGE_TYPE'] = $type; + $_SESSION['G_MESSAGE'] = $text; + $_SESSION['G_MESSAGE_TYPE'] = $type; } - private function getInUrlError() + private function getInUrlError () { - if (isset($_GET['errno'])) { + if (isset( $_GET['errno'] )) { switch ($_GET['errno']) { case '1': $trnLabel = 'ID_USER_HAVENT_RIGHTS_PAGE'; @@ -646,13 +639,13 @@ class Main extends Controller $trnLabel = 'ID_USER_HAVENT_RIGHTS_PAGE'; break; } - $this->setFlyNotify('error', 'ERROR', G::loadTranslation($trnLabel)); + $this->setFlyNotify( 'error', 'ERROR', G::loadTranslation( $trnLabel ) ); } } - private function getActiveTab($activeTab) + private function getActiveTab ($activeTab) { - if (!is_numeric($activeTab)) { + if (! is_numeric( $activeTab )) { switch ($activeTab) { case 'home': $activeTab = 0; @@ -671,118 +664,137 @@ class Main extends Controller break; } } else { - $activeTab = $activeTab > -1 && $activeTab < 3 ? (int) $activeTab : ''; + $activeTab = $activeTab > - 1 && $activeTab < 3 ? (int) $activeTab : ''; } return $activeTab; } - private function getUrlGetParams() + private function getUrlGetParams () { $urlGetParams = ''; foreach ($_GET as $key => $value) { $urlGetParams .= $urlGetParams == '' ? $key : "&" . $key; - $urlGetParams .= trim($value) != '' ? '=' . $value : ''; + $urlGetParams .= trim( $value ) != '' ? '=' . $value : ''; } return $urlGetParams; } - private function getUserFullName() + private function getUserFullName () { - return isset($_SESSION['USR_FULLNAME']) ? $_SESSION['USR_FULLNAME'] : ''; + return isset( $_SESSION['USR_FULLNAME'] ) ? $_SESSION['USR_FULLNAME'] : ''; } - private function _getSystemInfo() + private function _getSystemInfo () { - G::LoadClass("system"); + G::LoadClass( "system" ); - if (getenv('HTTP_CLIENT_IP')) { - $ip = getenv('HTTP_CLIENT_IP'); + if (getenv( 'HTTP_CLIENT_IP' )) { + $ip = getenv( 'HTTP_CLIENT_IP' ); } else { - if (getenv('HTTP_X_FORWARDED_FOR')) { - $ip = getenv('HTTP_X_FORWARDED_FOR'); + if (getenv( 'HTTP_X_FORWARDED_FOR' )) { + $ip = getenv( 'HTTP_X_FORWARDED_FOR' ); } else { - $ip = getenv('REMOTE_ADDR'); + $ip = getenv( 'REMOTE_ADDR' ); } } $redhat = ''; - if (file_exists ('/etc/redhat-release')) { - $fnewsize = filesize ('/etc/redhat-release'); - $fp = fopen ('/etc/redhat-release', 'r'); - $redhat = trim (fread ($fp, $fnewsize)); - fclose ($fp); + if (file_exists( '/etc/redhat-release' )) { + $fnewsize = filesize( '/etc/redhat-release' ); + $fp = fopen( '/etc/redhat-release', 'r' ); + $redhat = trim( fread( $fp, $fnewsize ) ); + fclose( $fp ); } $redhat .= " (" . PHP_OS . ")"; - if (defined ("DB_HOST")) { - G::LoadClass ('net'); - G::LoadClass ('dbConnections'); - $dbNetView = new NET (DB_HOST); - $dbNetView->loginDbServer (DB_USER, DB_PASS); + if (defined( "DB_HOST" )) { + G::LoadClass( 'net' ); + G::LoadClass( 'dbConnections' ); + $dbNetView = new NET( DB_HOST ); + $dbNetView->loginDbServer( DB_USER, DB_PASS ); - $dbConns = new dbConnections (''); + $dbConns = new dbConnections( '' ); $availdb = ''; - foreach ($dbConns->getDbServicesAvailables () as $key => $val) { + foreach ($dbConns->getDbServicesAvailables() as $key => $val) { if ($availdb != '') { $availdb .= ', '; } - $availdb .= $val ['name']; + $availdb .= $val['name']; } try { - $sMySQLVersion = $dbNetView->getDbServerVersion (DB_ADAPTER); + $sMySQLVersion = $dbNetView->getDbServerVersion( DB_ADAPTER ); } catch (Exception $oException) { $sMySQLVersion = '?????'; } } - $sysSection = G::loadTranslation('ID_SYSTEM_INFO'); - $pmSection = 'ProcessMaker Information'; + $sysSection = G::loadTranslation( 'ID_SYSTEM_INFO' ); + $pmSection = 'ProcessMaker Information'; - $properties = array(); - $ee = class_exists('pmLicenseManager') ? " - Enterprise Edition" : ''; - $properties[] = array('ProcessMaker Ver.', System::getVersion() . $ee, $pmSection); - $properties[] = array('Operating System', $redhat, $sysSection); - $properties[] = array('Time Zone', (defined('TIME_ZONE')) ? TIME_ZONE : "Unknown", $sysSection); - $properties[] = array('Web Server', getenv ('SERVER_SOFTWARE'), $sysSection); - $properties[] = array('Server Name', getenv ('SERVER_NAME'), $pmSection); - $properties[] = array('Server IP Address', $this->lookup ($ip), $sysSection); - $properties[] = array('PHP Version', phpversion(), $sysSection); + $properties = array (); + $ee = class_exists( 'pmLicenseManager' ) ? " - Enterprise Edition" : ''; + $properties[] = array ('ProcessMaker Ver.',System::getVersion() . $ee,$pmSection + ); + $properties[] = array ('Operating System',$redhat,$sysSection + ); + $properties[] = array ('Time Zone',(defined( 'TIME_ZONE' )) ? TIME_ZONE : "Unknown",$sysSection + ); + $properties[] = array ('Web Server',getenv( 'SERVER_SOFTWARE' ),$sysSection + ); + $properties[] = array ('Server Name',getenv( 'SERVER_NAME' ),$pmSection + ); + $properties[] = array ('Server IP Address',$this->lookup( $ip ),$sysSection + ); + $properties[] = array ('PHP Version',phpversion(),$sysSection + ); - if (defined ("DB_HOST")) { - $properties[] = array('Data Base', $dbNetView->dbName(DB_ADAPTER) . ' (Version ' . $sMySQLVersion . ')', - $pmSection); - $properties[] = array('Data Base Server', DB_HOST, $pmSection); - $properties[] = array('Data Base Name', DB_NAME, $pmSection); - $properties[] = array('Available DB Engines', $availdb, $sysSection); + if (defined( "DB_HOST" )) { + $properties[] = array ('Data Base',$dbNetView->dbName( DB_ADAPTER ) . ' (Version ' . $sMySQLVersion . ')',$pmSection + ); + $properties[] = array ('Data Base Server',DB_HOST,$pmSection + ); + $properties[] = array ('Data Base Name',DB_NAME,$pmSection + ); + $properties[] = array ('Available DB Engines',$availdb,$sysSection + ); } else { - $properties[] = array('Data Base', "Not defined", $pmSection); - $properties[] = array('Data Base Server', "Not defined", $pmSection); - $properties[] = array('Data Base Name', "Not defined", $pmSection); - $properties[] = array('Available DB Engines', "Not defined", $sysSection); + $properties[] = array ('Data Base',"Not defined",$pmSection + ); + $properties[] = array ('Data Base Server',"Not defined",$pmSection + ); + $properties[] = array ('Data Base Name',"Not defined",$pmSection + ); + $properties[] = array ('Available DB Engines',"Not defined",$sysSection + ); } - $properties[] = array('Workspace', defined ("SYS_SYS") ? SYS_SYS : "Not defined", $pmSection); + $properties[] = array ('Workspace',defined( "SYS_SYS" ) ? SYS_SYS : "Not defined",$pmSection + ); - $properties[] = array('Server Protocol', getenv ('SERVER_PROTOCOL'), $sysSection); - $properties[] = array('Server Port', getenv ('SERVER_PORT'), $sysSection); + $properties[] = array ('Server Protocol',getenv( 'SERVER_PROTOCOL' ),$sysSection + ); + $properties[] = array ('Server Port',getenv( 'SERVER_PORT' ),$sysSection + ); //$properties[] = array('Remote Host', getenv ('REMOTE_HOST'), $sysSection); - $properties[] = array('Server Addr.', getenv ('SERVER_ADDR'), $sysSection); - $properties[] = array('User\'s Browser', getenv ('HTTP_USER_AGENT'), $sysSection); + $properties[] = array ('Server Addr.',getenv( 'SERVER_ADDR' ),$sysSection + ); + $properties[] = array ('User\'s Browser',getenv( 'HTTP_USER_AGENT' ),$sysSection + ); return $properties; } - private function lookup($target) + private function lookup ($target) { global $ntarget; $msg = $target . ' => '; //if (eregi ('[a-zA-Z]', $target)) - if (preg_match('[a-zA-Z]', $target)) { + if (preg_match( '[a-zA-Z]', $target )) { //Made compatible to PHP 5.3 - $ntarget = gethostbyname ($target); + $ntarget = gethostbyname( $target ); } else { - $ntarget = gethostbyaddr ($target); + $ntarget = gethostbyaddr( $target ); } $msg .= $ntarget; return ($msg); @@ -791,9 +803,9 @@ class Main extends Controller /** * Execute common reoutes after index() action load */ - private function afterLoad($httpData) + private function afterLoad ($httpData) { - if (isset($httpData->i18) || isset($httpData->i18n)) { + if (isset( $httpData->i18 ) || isset( $httpData->i18n )) { $_SESSION['DEV_FLAG'] = true; } }