/** * Constructor of the class * * return void */ public function __construct() { try { $user = new \ProcessMaker\BusinessModel\User(); $usrUid = $this->getUserId(); if (!$user->checkPermission($usrUid, "PM_SETUP")) { throw new \Exception(\G::LoadTranslation("ID_USER_NOT_HAVE_PERMISSION", array($usrUid))); } } catch (\Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); } }
/** * Constructor of the class * * return void */ public function __construct() { try { $user = new \ProcessMaker\BusinessModel\User(); $usrUid = $this->getUserId(); if (!$user->checkPermission($usrUid, "PM_USERS")) { throw new \Exception(\G::LoadTranslation("ID_USER_NOT_HAVE_PERMISSION", array($usrUid))); } $this->role = new \ProcessMaker\BusinessModel\Role(); $this->role->setFormatFieldNameInUppercase(false); } catch (\Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); } }
/** * Get list for Cases * * @access public * @param array $dataList, Data for list * @return array * * @author Brayan Pereyra (Cochalo) <*****@*****.**> * @copyright Colosa - Bolivia */ public function getList($dataList = array()) { Validator::isArray($dataList, '$dataList'); if (!isset($dataList["userId"])) { throw (new \Exception(\G::LoadTranslation("ID_USER_NOT_EXIST", array('userId','')))); } else { Validator::usrUid($dataList["userId"], "userId"); } $user = new \ProcessMaker\BusinessModel\User(); if (!$user->checkPermission($dataList["userId"], "PM_ALLCASES")) { throw new \Exception(\G::LoadTranslation("ID_CASE_USER_NOT_HAVE_PERMISSION", array($dataList["userId"]))); } G::LoadClass("applications"); $solrEnabled = false; $userUid = $dataList["userId"]; $callback = isset( $dataList["callback"] ) ? $dataList["callback"] : "stcCallback1001"; $dir = isset( $dataList["dir"] ) ? $dataList["dir"] : "DESC"; $sort = isset( $dataList["sort"] ) ? $dataList["sort"] : "APP_CACHE_VIEW.APP_NUMBER"; $start = isset( $dataList["start"] ) ? $dataList["start"] : "0"; $limit = isset( $dataList["limit"] ) ? $dataList["limit"] : ""; $filter = isset( $dataList["filter"] ) ? $dataList["filter"] : ""; $process = isset( $dataList["process"] ) ? $dataList["process"] : ""; $category = isset( $dataList["category"] ) ? $dataList["category"] : ""; $status = isset( $dataList["status"] ) ? strtoupper( $dataList["status"] ) : ""; $user = isset( $dataList["user"] ) ? $dataList["user"] : ""; $search = isset( $dataList["search"] ) ? $dataList["search"] : ""; $action = isset( $dataList["action"] ) ? $dataList["action"] : "todo"; $paged = isset( $dataList["paged"] ) ? $dataList["paged"] : true; $type = "extjs"; $dateFrom = (!empty( $dataList["dateFrom"] )) ? substr( $dataList["dateFrom"], 0, 10 ) : ""; $dateTo = (!empty( $dataList["dateTo"] )) ? substr( $dataList["dateTo"], 0, 10 ) : ""; $first = isset( $dataList["first"] ) ? true :false; $valuesCorrect = array('todo', 'draft', 'paused', 'sent', 'selfservice', 'unassigned', 'search'); if (!in_array($action, $valuesCorrect)) { throw (new \Exception(\G::LoadTranslation("ID_INCORRECT_VALUE_ACTION"))); } $start = (int)$start; $start = abs($start); if ($start != 0) { $start--; } $limit = (int)$limit; $limit = abs($limit); if ($limit == 0) { G::LoadClass("configuration"); $conf = new \Configurations(); $generalConfCasesList = $conf->getConfiguration('ENVIRONMENT_SETTINGS', ''); if (isset($generalConfCasesList['casesListRowNumber'])) { $limit = (int)$generalConfCasesList['casesListRowNumber']; } else { $limit = 25; } } else { $limit = (int)$limit; } if ($sort != 'APP_CACHE_VIEW.APP_NUMBER') { $sort = G::toUpper($sort); $columnsAppCacheView = \AppCacheViewPeer::getFieldNames(\BasePeer::TYPE_FIELDNAME); if (!(in_array($sort, $columnsAppCacheView))) { $sort = 'APP_CACHE_VIEW.APP_NUMBER'; } } $dir = G::toUpper($dir); if (!($dir == 'DESC' || $dir == 'ASC')) { $dir = 'DESC'; } if ($process != '') { Validator::proUid($process, '$pro_uid'); } if ($category != '') { Validator::catUid($category, '$cat_uid'); } $status = G::toUpper($status); $listStatus = array('TO_DO', 'DRAFT', 'COMPLETED', 'CANCEL', 'OPEN', 'CLOSE'); if (!(in_array($status, $listStatus))) { $status = ''; } if ($user != '') { Validator::usrUid($user, '$usr_uid'); } if ($dateFrom != '') { Validator::isDate($dateFrom, 'Y-m-d', '$date_from'); } if ($dateTo != '') { Validator::isDate($dateTo, 'Y-m-d', '$date_to'); } if ($action == 'search' || $action == 'to_reassign') { $userUid = ($user == "CURRENT_USER") ? $userUid : $user; if ($first) { $result = array(); $result['totalCount'] = 0; $result['data'] = array(); return $result; } } if (( $action == "todo" || $action == "draft" || $action == "paused" || $action == "sent" || $action == "selfservice" || $action == "unassigned" || $action == "search" ) && (($solrConf = \System::solrEnv()) !== false) ) { G::LoadClass("AppSolr"); $ApplicationSolrIndex = new \AppSolr( $solrConf["solr_enabled"], $solrConf["solr_host"], $solrConf["solr_instance"] ); if ($ApplicationSolrIndex->isSolrEnabled() && $solrConf['solr_enabled'] == true) { //Check if there are missing records to reindex and reindex them $ApplicationSolrIndex->synchronizePendingApplications(); $solrEnabled = true; } } if ($solrEnabled) { $result = $ApplicationSolrIndex->getAppGridData( $userUid, $start, $limit, $action, $filter, $search, $process, $status, $type, $dateFrom, $dateTo, $callback, $dir, $sort, $category ); } else { G::LoadClass("applications"); $apps = new \Applications(); $result = $apps->getAll( $userUid, $start, $limit, $action, $filter, $search, $process, $status, $type, $dateFrom, $dateTo, $callback, $dir, (strpos($sort, ".") !== false)? $sort : "APP_CACHE_VIEW." . $sort, $category, true, $paged ); } if (!empty($result['data'])) { foreach ($result['data'] as &$value) { $value = array_change_key_case($value, CASE_LOWER); } } if ($paged == false) { $response = $result['data']; } else { $response['total'] = $result['totalCount']; $response['start'] = $start+1; $response['limit'] = $limit; $response['sort'] = G::toLower($sort); $response['dir'] = G::toLower($dir); $response['cat_uid'] = $category; $response['pro_uid'] = $process; $response['search'] = $search; if ($action == 'search') { $response['app_status'] = G::toLower($status); $response['usr_uid'] = $user; $response['date_from'] = $dateFrom; $response['date_to'] = $dateTo; } $response['data'] = $result['data']; } return $response; }
/** * Index Action * * @param string $httpData (opional) */ public function index($httpData) { $proUid = isset($httpData->prj_uid) ? $httpData->prj_uid : ''; $appUid = isset($httpData->app_uid) ? $httpData->app_uid : ''; $proReadOnly = isset($httpData->prj_readonly) ? $httpData->prj_readonly : 'false'; $client = $this->getClientCredentials(); if (isset($httpData->tracker_designer) && $httpData->tracker_designer == 1) { $client["tracker_designer"] = 1; } $authCode = $this->getAuthorizationCode($client); $debug = false; //System::isDebugMode(); $loader = Maveriks\Util\ClassLoader::getInstance(); $loader->add(PATH_TRUNK . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2"); $request = array('grant_type' => 'authorization_code', 'code' => $authCode); $server = array('REQUEST_METHOD' => 'POST'); $headers = array("PHP_AUTH_USER" => $client['CLIENT_ID'], "PHP_AUTH_PW" => $client['CLIENT_SECRET'], "Content-Type" => "multipart/form-data;", "Authorization" => "Basic " . base64_encode($client['CLIENT_ID'] . ":" . $client['CLIENT_SECRET'])); $request = new \OAuth2\Request(array(), $request, array(), array(), array(), $server, null, $headers); $oauthServer = new \ProcessMaker\Services\OAuth2\Server(); $response = $oauthServer->postToken($request, true); $clientToken = $response->getParameters(); $clientToken["client_id"] = $client['CLIENT_ID']; $clientToken["client_secret"] = $client['CLIENT_SECRET']; $consolidated = 0; $enterprise = 0; $distribution = 0; /*----------------------------------********---------------------------------*/ $this->setVar('prj_uid', $proUid); $this->setVar('app_uid', $appUid); $this->setVar('consolidated', $consolidated); $this->setVar('enterprise', $enterprise); $this->setVar('prj_readonly', $proReadOnly); $this->setVar('credentials', base64_encode(json_encode($clientToken))); $this->setVar('isDebugMode', $debug); $this->setVar("distribution", $distribution); $this->setVar("SYS_SYS", SYS_SYS); $this->setVar("SYS_LANG", SYS_LANG); $this->setVar("SYS_SKIN", SYS_SKIN); if ($debug) { if (!file_exists(PATH_HTML . "lib-dev/pmUI/build.cache")) { throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in pmUI project"); } if (!file_exists(PATH_HTML . "lib-dev/mafe/build.cache")) { throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in MichelangeloFE project"); } $mafeFiles = file(PATH_HTML . "lib-dev/mafe/build.cache", FILE_IGNORE_NEW_LINES); $mafeCssFiles = array(); $mafeJsFiles = array(); foreach ($mafeFiles as $file) { if (substr($file, -3) == ".js") { $mafeJsFiles[] = $file; } else { $mafeCssFiles[] = $file; } } $this->setVar('pmuiJsCacheFile', file(PATH_HTML . "lib-dev/pmUI/build.cache", FILE_IGNORE_NEW_LINES)); $this->setVar('pmuiCssCacheFile', file(PATH_HTML . "lib-dev/pmUI/css.cache", FILE_IGNORE_NEW_LINES)); $this->setVar('designerCacheFile', file(PATH_HTML . "lib-dev/mafe/applications.cache", FILE_IGNORE_NEW_LINES)); $this->setVar('mafeJsFiles', $mafeJsFiles); $this->setVar('mafeCssFiles', $mafeCssFiles); } else { $buildhashFile = PATH_HTML . "lib/buildhash"; if (!file_exists($buildhashFile)) { throw new RuntimeException("CSS and JS Files were are not generated!.\nPlease review install process"); } $buildhash = file_get_contents($buildhashFile); $this->setVar('buildhash', $buildhash); } $translationMafe = "/translations/translationsMafe.js"; $this->setVar('translationMafe', $translationMafe); if (!file_exists(PATH_HTML . "translations" . PATH_SEP . 'translationsMafe' . ".js")) { $translation = new Translation(); $translation->generateFileTranslationMafe(); } $this->setVar('sys_skin', SYS_SKIN); //Verify user $criteria = new Criteria('workflow'); $criteria->addSelectColumn(OauthAccessTokensPeer::ACCESS_TOKEN); $criteria->addSelectColumn(OauthAccessTokensPeer::USER_ID); $criteria->add(OauthAccessTokensPeer::ACCESS_TOKEN, $clientToken['access_token'], Criteria::EQUAL); $rsCriteria = OauthAccessTokensPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); if ($rsCriteria->next()) { $row = $rsCriteria->getRow(); $user = new \ProcessMaker\BusinessModel\User(); if ($user->checkPermission($row['USER_ID'], 'PM_FACTORY')) { $this->setView('designer/index'); } else { $this->setVar('accessDenied', G::LoadTranslation('ID_ACCESS_DENIED')); $this->setView('designer/accessDenied'); } } $this->render(); }