diff --git a/workflow/engine/controllers/home.php b/workflow/engine/controllers/home.php index 54fb21631..c298b5a59 100644 --- a/workflow/engine/controllers/home.php +++ b/workflow/engine/controllers/home.php @@ -22,6 +22,7 @@ class Home extends Controller private $clientBrowser; private $lastSkin; + private $usrId; public function __construct () { @@ -39,6 +40,10 @@ class Home extends Controller $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'] : ''; + + $users = new Users(); + $users = $users->load($this->userID); + $this->usrId = $users["USR_ID"]; } } @@ -261,7 +266,6 @@ class Home extends Controller // settings vars and rendering $this->setVar( 'cases', $cases['data'] ); - $this->setVar( 'cases_count', $cases['totalCount'] ); $this->setVar( 'title', $title ); $this->setVar( 'noPerms', G::LoadTranslation( 'ID_CASES_NOTES_NO_PERMISSIONS' )); $this->setVar( 'appListStart', $this->appListLimit ); @@ -279,6 +283,7 @@ class Home extends Controller // settings html template $this->setView( $this->userUxBaseTemplate . PATH_SEP . 'appListSearch' ); + // get data $process = (isset($httpData->process)) ? $httpData->process : null; $status = (isset($httpData->status)) ? $httpData->status : null; $search = (isset($httpData->search)) ? $httpData->search : null; @@ -286,18 +291,16 @@ class Home extends Controller $user = (isset($httpData->user)) ? $httpData->user : null; $dateFrom = (isset($httpData->dateFrom)) ? $httpData->dateFrom : null; $dateTo = (isset($httpData->dateTo)) ? $httpData->dateTo : null; + $processTitle = ""; if (!empty($process)) { $processTitle = Process::loadById($process)->getProTitle(); - } else { - $processTitle = ''; } - if (!empty($user)) { + $userName = ""; + if (!empty($user) && $user !== "ALL" && $user !== "CURRENT_USER") { $userObject = Users::loadById($user); - $userName = $userObject->getUsrLastname()." ".$userObject->getUsrFirstname(); - } else { - $userName = ''; + $userName = $userObject->getUsrLastname() . " " . $userObject->getUsrFirstname(); } - + $cases = $this->getAppsData( $httpData->t, null, null, $user, null, $search, $process, $status, $dateFrom, $dateTo, null, null, 'APP_CACHE_VIEW.APP_NUMBER', $category); $arraySearch = array($process, $status, $search, $category, $user, $dateFrom, $dateTo ); @@ -318,7 +321,6 @@ class Home extends Controller $this->setVar( 'arraySearch', $arraySearch ); $this->setVar( 'cases', $cases['data'] ); - $this->setVar( 'cases_count', $cases['totalCount'] ); $this->setVar( 'title', $title ); $this->setVar( 'noPerms', G::LoadTranslation( 'ID_CASES_NOTES_NO_PERMISSIONS' )); $this->setVar( 'appListStart', $this->appListLimit ); @@ -369,13 +371,13 @@ class Home extends Controller $notesLimit = 4; switch ($user) { case 'CURRENT_USER': - $user = $this->userID; + $user = $this->usrId; break; case 'ALL': $user = null; break; case null: - $user = $this->userID; + $user = $this->usrId; break; default: //$user = $this->userID; @@ -444,21 +446,15 @@ class Home extends Controller if (true) { //In enterprise version this block of code should always be executed //In community version this block of code is deleted and is executed the other - $list = new \ProcessMaker\BusinessModel\Lists(); - $listName = 'inbox'; - switch ($type) { - case 'draft': - case 'todo': - $listName = 'inbox'; - $cases = $list->getList($listName, $dataList); - break; - case 'unassigned': - $case = new \ProcessMaker\BusinessModel\Cases(); - $cases = $case->getList($dataList); - foreach ($cases['data'] as &$value) { - $value = array_change_key_case($value, CASE_UPPER); - } - break; + $swType = $type === "todo" || $type === "draft"; + if ($swType || $type === "unassigned") { + //The change is made because the method 'getList()' does not + //support 'USR_UID', this method uses the numeric field 'USR_ID'. + $userObject = Users::loadById($dataList['userId']); + $dataList['userId'] = $userObject->getUsrUid(); + $listType = $swType ? "inbox" : $type; + $list = new \ProcessMaker\BusinessModel\Lists(); + $cases = $list->getList($listType, $dataList); } } else { /*----------------------------------********---------------------------------*/ @@ -559,31 +555,32 @@ class Home extends Controller $this->render(); } - function getUserArray ($action, $userUid, $search = null) + function getUserArray($action, $userUid, $search = null) { global $oAppCache; - $status = array (); - $users[] = array ("CURRENT_USER",G::LoadTranslation( "ID_CURRENT_USER" )); - $users[] = array ("ALL",G::LoadTranslation( "ID_ALL_USERS" )); + $status = array(); + $users[] = array("CURRENT_USER", G::LoadTranslation("ID_CURRENT_USER")); + $users[] = array("ALL", G::LoadTranslation("ID_ALL_USERS")); //now get users, just for the Search action switch ($action) { case 'search_simple': case 'search': - $cUsers = new Criteria( 'workflow' ); + $cUsers = new Criteria('workflow'); $cUsers->clearSelectColumns(); - $cUsers->addSelectColumn( UsersPeer::USR_UID ); - $cUsers->addSelectColumn( UsersPeer::USR_FIRSTNAME ); - $cUsers->addSelectColumn( UsersPeer::USR_LASTNAME ); + $cUsers->addSelectColumn(UsersPeer::USR_UID); + $cUsers->addSelectColumn(UsersPeer::USR_FIRSTNAME); + $cUsers->addSelectColumn(UsersPeer::USR_LASTNAME); + $cUsers->addSelectColumn(UsersPeer::USR_ID); if (!empty($search)) { $cUsers->addOr(UsersPeer::USR_FIRSTNAME, "%$search%", Criteria::LIKE); $cUsers->addOr(UsersPeer::USR_LASTNAME, "%$search%", Criteria::LIKE); } - $oDataset = UsersPeer::doSelectRS( $cUsers ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset = UsersPeer::doSelectRS($cUsers); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); while ($aRow = $oDataset->getRow()) { - $users[] = array ($aRow['USR_UID'], htmlentities($aRow['USR_LASTNAME'] . ' ' . $aRow['USR_FIRSTNAME'], ENT_QUOTES, "UTF-8")); + $users[] = array($aRow['USR_ID'], htmlentities($aRow['USR_LASTNAME'] . ' ' . $aRow['USR_FIRSTNAME'], ENT_QUOTES, "UTF-8")); $oDataset->next(); } break; diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index fd651d249..ba1cbc5e8 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -227,9 +227,7 @@ class Cases { 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"); + $dataList["userId"] = null; } $solrEnabled = false; diff --git a/workflow/engine/src/ProcessMaker/Util/System.php b/workflow/engine/src/ProcessMaker/Util/System.php index 0424e6303..e1135f083 100644 --- a/workflow/engine/src/ProcessMaker/Util/System.php +++ b/workflow/engine/src/ProcessMaker/Util/System.php @@ -1,12 +1,20 @@ 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 Request(array(), $request, array(), array(), array(), $server, null, $headers); + $oauthServer = new Server(); + $response = $oauthServer->postToken($request, true); + $clientToken = $response->getParameters(); + $clientToken["client_id"] = $client['CLIENT_ID']; + $clientToken["client_secret"] = $client['CLIENT_SECRET']; + return $clientToken; + } + + /** + * Get client credentials + * @return array + */ + protected function getClientCredentials() + { + $oauthQuery = new PmPdo(self::getDsn()); + return $oauthQuery->getClientDetails(self::CLIENT_ID); + } + + /** + * Get DNS of workspace + * @return array + */ + protected function getDsn() + { + list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, ''); + $port = empty($port) ? '' : ";port=$port"; + $dsn = DB_ADAPTER . ':host=' . $host . ';dbname=' . DB_NAME . $port; + + return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS); + } + + /** + * Get authorization code for user logged in session + * @param $client + * @return bool|string + */ + protected function getAuthorizationCodeUserLogged($client) + { + Server::setDatabaseSource(self::getDsn()); + Server::setPmClientId($client['CLIENT_ID']); + + $oauthServer = new Server(); + + $userId = $_SESSION['USER_LOGGED']; + $authorize = true; + $_GET = array_merge($_GET, array( + 'response_type' => 'code', + 'client_id' => $client['CLIENT_ID'], + 'scope' => implode(' ', $oauthServer->getScope()) + )); + + $response = $oauthServer->postAuthorize($authorize, $userId, true); + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); + return $code; + } } diff --git a/workflow/engine/templates/home/appList.html b/workflow/engine/templates/home/appList.html index aa9807248..f5552928b 100644 --- a/workflow/engine/templates/home/appList.html +++ b/workflow/engine/templates/home/appList.html @@ -173,7 +173,7 @@