function index() { $auth = $this->authenticate(); if (!$auth) { $this->error('401', 'Not logged in.'); return; } if ($auth[2] != 'god') { $this->error('403', 'Applications can only be authenticated/revoked/listed via the Koken console.'); return; } if ($this->method === 'post') { $_POST['token'] = koken_rand(); $a = new Application(); $a->from_array($_POST, array(), true); $this->redirect('/auth/token:' . $auth[1]); } if ($this->method === 'delete') { list($params, $id) = $this->parse_params(func_get_args()); $a = new Application(); $a->where('id', $id)->get(); if ($a->exists()) { $a->delete(); $this->redirect('/auth/token:' . $auth[1]); } } $a = new Application(); $a->where('role !=', 'god')->get_iterated(); $apps = array(); foreach ($a as $app) { $apps[] = $app->to_array(); } $this->set_response_data(array('applications' => $apps)); }
/** * Get the [app_title] column value. * @return string */ public function getAppTitle() { $oApplication = new Application(); if (!$oApplication->exists($this->getAppUid())) { return false; } if ($this->getAppUid() == '') { throw new Exception("Error in getAppTitle, the APP_UID can't be blank"); } $lang = defined('SYS_LANG') ? SYS_LANG : 'en'; $this->app_title = Content::load('APP_TITLE', '', $this->getAppUid(), $lang); return $this->app_title; }
public function auth() { $client_id = $this->input->get('clent_id'); $application = new Application(); $application->client_id = $client_id; $application->get(); if (!$application->exists()) { $data['title'] = 'Auth Page'; $data['content'] = 'oauth/noapplication'; $this->load->view('master', $data); } elseif (!$this->user_id) { $redirect = 'users/login?redirect_url=oauth/auth?client_id=' . $application->id; redirect($redirect); } elseif ($this->input->post()) { $allow = $this->input->post('allow'); if ($allow) { $user = new User($this->user_id); $existing_token = new Token(); $existing_token->where('user_id', $user->id); $existing_token->where('application_id', $application->id); $existing_token->get(); if ($existing_token->exists()) { $existing_token->delete(); } $token = $this->generate_token(); $token->save(array($application, $user)); die; echo 'here'; } } else { $this->load->helper('form'); $data['application'] = array('id' => $application->id, 'name' => $application->name, 'client_id' => $application->client_id, 'client_secret' => $application->client_secret, 'redirect_url' => $application->redirect_url); $data['title'] = 'Auth Page'; $data['content'] = 'oauth/authorize'; $this->load->view('master', $data); } }
<?php $a = new Application(); $a->where('token', '69ad71aa4e07e9338ac49d33d041941b')->get(); if ($a->exists()) { $a->delete(); } $done = true;
public function updateCase($sAppUid, $Fields = array()) { try { $dynContentHistory = ""; if (isset($Fields["APP_DATA"]) && isset($Fields["APP_DATA"]["DYN_CONTENT_HISTORY"])) { $dynContentHistory = $Fields["APP_DATA"]["DYN_CONTENT_HISTORY"]; unset($Fields["APP_DATA"]["DYN_CONTENT_HISTORY"]); } $oApplication = new Application; if (!$oApplication->exists($sAppUid)) { return false; } $aApplicationFields = $Fields['APP_DATA']; $Fields['APP_UID'] = $sAppUid; $Fields['APP_UPDATE_DATE'] = 'now'; $Fields['APP_DATA'] = serialize($Fields['APP_DATA']); /* $oApp = new Application; $appFields = $oApp->load($sAppUid); */ $oApp = ApplicationPeer::retrieveByPk($sAppUid); $appFields = $oApp->toArray(BasePeer::TYPE_FIELDNAME); if (isset($Fields['APP_TITLE'])) { $appFields['APP_TITLE'] = $Fields['APP_TITLE']; } if (isset($Fields['APP_DESCRIPTION'])) { $appFields['APP_DESCRIPTION'] = $Fields['APP_DESCRIPTION']; } $arrayNewCaseTitleAndDescription = $this->newRefreshCaseTitleAndDescription($sAppUid, $appFields, $aApplicationFields); //Start: Save History --By JHL if (isset($Fields['CURRENT_DYNAFORM'])) { //only when that variable is set.. from Save $FieldsBefore = $this->loadCase($sAppUid); $FieldsDifference = $this->arrayRecursiveDiff($FieldsBefore['APP_DATA'], $aApplicationFields); $fieldsOnBoth = @array_intersect_assoc($FieldsBefore['APP_DATA'], $aApplicationFields); //Add fields that weren't in previous version foreach ($aApplicationFields as $key => $value) { if (!(isset($fieldsOnBoth[$key]))) { $FieldsDifference[$key] = $value; } } if ((is_array($FieldsDifference)) && (count($FieldsDifference) > 0)) { //There are changes $Fields['APP_STATUS'] = (isset($Fields['APP_STATUS'])) ? $Fields['APP_STATUS'] : $FieldsBefore['APP_STATUS']; $appHistory = new AppHistory(); $aFieldsHistory = $Fields; $FieldsDifference['DYN_CONTENT_HISTORY'] = $dynContentHistory; $aFieldsHistory['APP_DATA'] = serialize($FieldsDifference); $appHistory->insertHistory($aFieldsHistory); } } //End Save History //we are removing the app_title and app_description from this array, //because they already be updated in newRefreshCaseTitleAndDescription function if (isset($Fields['APP_TITLE'])) { unset($Fields['APP_TITLE']); } if (isset($Fields['APP_DESCRIPTION'])) { unset($Fields['APP_DESCRIPTION']); } if (isset($Fields["APP_STATUS"]) && $Fields["APP_STATUS"] == "COMPLETED") { if (isset($Fields['CURRENT_USER_UID'])) { $Fields['USR_UID'] = $Fields['CURRENT_USER_UID']; } /*----------------------------------********---------------------------------*/ } $oApp->update($Fields); $DEL_INDEX = isset($Fields['DEL_INDEX']) ? $Fields['DEL_INDEX'] : ''; $TAS_UID = isset($Fields['TAS_UID']) ? $Fields['TAS_UID'] : ''; G::LoadClass('reportTables'); require_once 'classes/model/AdditionalTables.php'; $oReportTables = new ReportTables(); $addtionalTables = new additionalTables(); if (!isset($Fields['APP_NUMBER'])) { $Fields['APP_NUMBER'] = $appFields['APP_NUMBER']; } if (!isset($Fields['APP_STATUS'])) { $Fields['APP_STATUS'] = $appFields['APP_STATUS']; } $oReportTables->updateTables($appFields['PRO_UID'], $sAppUid, $Fields['APP_NUMBER'], $aApplicationFields); $addtionalTables->updateReportTables( $appFields['PRO_UID'], $sAppUid, $Fields['APP_NUMBER'], $aApplicationFields, $Fields['APP_STATUS'] ); //now update the priority in appdelegation table, using the defined variable in task if (trim($DEL_INDEX) != '' && trim($TAS_UID) != '') { //optimized code to avoid load task content row. $c = new Criteria(); $c->clearSelectColumns(); $c->addSelectColumn(TaskPeer::TAS_PRIORITY_VARIABLE); $c->add(TaskPeer::TAS_UID, $TAS_UID); $rs = TaskPeer::doSelectRS($c); $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); $rs->next(); $row = $rs->getRow(); $VAR_PRI = substr($row['TAS_PRIORITY_VARIABLE'], 2); //end optimized code. $x = unserialize($Fields['APP_DATA']); if (isset($x[$VAR_PRI])) { if (trim($x[$VAR_PRI]) != '') { $oDel = new AppDelegation; $array = array(); $array['APP_UID'] = $sAppUid; $array['DEL_INDEX'] = $DEL_INDEX; $array['TAS_UID'] = $TAS_UID; $array['DEL_PRIORITY'] = (isset($x[$VAR_PRI]) ? ($x[$VAR_PRI] >= 1 && $x[$VAR_PRI] <= 5 ? $x[$VAR_PRI] : '3') : '3'); $oDel->update($array); } } } //Update Solr Index if ($this->appSolr != null) { $this->appSolr->updateApplicationSearchIndex($sAppUid); } if ($Fields["APP_STATUS"] == "COMPLETED") { //Delete records of the table APP_ASSIGN_SELF_SERVICE_VALUE $appAssignSelfServiceValue = new AppAssignSelfServiceValue(); $appAssignSelfServiceValue->remove($sAppUid); } /*----------------------------------********---------------------------------*/ //Return return $Fields; } catch (exception $e) { throw ($e); } }
public function refreshCaseLabel($sAppUid, $aAppData, $sLabel) { $getAppLabel = "getApp{$sLabel}"; $getTasDef = "getTasDef{$sLabel}"; $oApplication = new Application(); if (!$oApplication->exists($sAppUid)) { return null; } else { $oApplication->load($sAppUid); $appLabel = $oApplication->{$getAppLabel}(); } $cri = new Criteria(); $cri->add(AppDelegationPeer::APP_UID, $sAppUid); $cri->add(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN"); $currentDelegations = AppDelegationPeer::doSelect($cri); for ($r = count($currentDelegations) - 1; $r >= 0; $r--) { $task = TaskPeer::retrieveByPk($currentDelegations[$r]->getTasUid()); $caseLabel = $task->{$getTasDef}(); if ($caseLabel != '') { $appLabel = G::replaceDataField($caseLabel, $aAppData); break; } } return $appLabel; }
public function getCompleteDocumentInfo ($appUid, $appDocUid, $docVersion, $docUid, $usrId) { //require_once ("classes/model/AppDocument.php"); //require_once ("classes/model/InputDocument.php"); //require_once ("classes/model/OutputDocument.php"); //require_once ("classes/model/Users.php"); //**** start get Doc Info $oApp = new Application(); $oAppDocument = new AppDocument(); G::LoadClass( 'case' ); $oCase = new Cases(); G::LoadClass( 'process' ); $oProcess = new Process(); if (($oApp->exists( $appUid )) || ($appUid == "00000000000000000000000000000000")) { if ($appUid == "00000000000000000000000000000000") { //External Files $row1 = $oAppDocument->load( $appDocUid, $docVersion ); $row2 = array ('PRO_TITLE' => G::LoadTranslation( 'ID_NOT_PROCESS_RELATED' )); $row3 = array ('APP_TITLE' => G::LoadTranslation( 'ID_NOT_PROCESS_RELATED' )); } else { $row1 = $oAppDocument->load( $appDocUid, $docVersion ); $row2 = $oCase->loadCase( $appUid ); $row3 = $oProcess->Load( $row2['PRO_UID'] ); } $lastVersion = $oAppDocument->getLastAppDocVersion( $appDocUid, $appUid ); switch ($row1['APP_DOC_TYPE']) { case "OUTPUT": $oOutputDocument = new OutputDocument(); $row4 = array(); $swOutDocExists = 0; if ($oOutputDocument->OutputExists($docUid)) { $row4 = $oOutputDocument->load($docUid); $swOutDocExists = 1; } if ($swOutDocExists == 0) { $swpdf = 0; $swdoc = 0; $info = pathinfo($oAppDocument->getAppDocFilename()); $version = (!empty($docVersion))? "_" . $docVersion : "_1"; $outDocPath = PATH_DOCUMENT . G::getPathFromUID($row1["APP_UID"]) . PATH_SEP . "outdocs" . PATH_SEP; if (file_exists($outDocPath . $appDocUid . $version . ".pdf") || file_exists($outDocPath . $info["basename"] . $version . ".pdf") || file_exists($outDocPath . $info["basename"] . ".pdf") ) { $swpdf = 1; } if (file_exists($outDocPath . $appDocUid . $version . ".doc") || file_exists($outDocPath . $info["basename"] . $version . ".doc") || file_exists($outDocPath . $info["basename"] . ".doc") ) { $swdoc = 1; } if ($swpdf == 1 && $swdoc == 1) { $row4["OUT_DOC_GENERATE"] = "BOTH"; } else { if ($swpdf == 1) { $row4["OUT_DOC_GENERATE"] = "PDF"; } else { if ($swdoc == 1) { $row4["OUT_DOC_GENERATE"] = "DOC"; } else { $row4["OUT_DOC_GENERATE"] = "NOFILE"; } } } } $versioningEnabled = false; //$row4['OUT_DOC_VERSIONING']; //Only enabled for Input or Attached documents. Need to study the best way for Output docs. switch ($row4['OUT_DOC_GENERATE']) { case "PDF": $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand(); $downloadLink1 = ""; $downloadLabel = ".pdf"; $downloadLabel1 = ""; break; case "DOC": $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand(); $downloadLink1 = ""; $downloadLabel = ".doc"; $downloadLabel1 = ""; break; case "BOTH": $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand(); $downloadLink1 = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand(); $downloadLabel = ".pdf"; $downloadLabel1 = ".doc"; break; case "NOFILE": $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink1 = ""; $downloadLabel = G::LoadTranslation("ID_DOWNLOAD"); $downloadLabel1 = ""; break; } if ($swOutDocExists == 0) { $row4 = array(); } break; case "INPUT": $oInputDocument = new InputDocument(); if ($docUid != - 1) { if ($oInputDocument->InputExists( $docUid )) { $row4 = $oInputDocument->load( $docUid ); $versioningEnabled = $row4['INP_DOC_VERSIONING']; } else { $row4 = array (); $versioningEnabled = false; } $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink1 = ""; $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' ); $downloadLabel1 = ""; } else { $row4 = array (); $versioningEnabled = false; $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink1 = ""; $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' ); $downloadLabel1 = ""; } if (! empty( $row1["APP_DOC_PLUGIN"] )) { $pluginRegistry = &PMPluginRegistry::getSingleton(); $pluginName = $row1["APP_DOC_PLUGIN"]; $fieldValue = ""; if (file_exists( PATH_PLUGINS . $pluginName . ".php" )) { $pluginDetail = $pluginRegistry->getPluginDetails( $pluginName . ".php" ); if ($pluginDetail) { if ($pluginDetail->enabled) { require_once (PATH_PLUGINS . $pluginName . ".php"); $pluginNameClass = $pluginName . "Plugin"; $objPluginClass = new $pluginNameClass( $pluginName ); if (isset( $objPluginClass->sMethodGetUrlDownload ) && ! empty( $objPluginClass->sMethodGetUrlDownload )) { if (file_exists( PATH_PLUGINS . $pluginName . PATH_SEP . "class." . $pluginName . ".php" )) { require_once (PATH_PLUGINS . $pluginName . PATH_SEP . "class." . $pluginName . ".php"); $pluginNameClass = $pluginName . "Class"; $objClass = new $pluginNameClass(); if (method_exists( $objClass, $objPluginClass->sMethodGetUrlDownload )) { eval( "\$url = \$objClass->" . $objPluginClass->sMethodGetUrlDownload . "(\"" . $row1["APP_DOC_UID"] . "\");" ); $downloadLink = $url; $fieldValue = $row1["APP_DOC_PLUGIN"]; } } } } } } $row1["APP_DOC_PLUGIN"] = $fieldValue; } break; default: $row4 = array (); $versioningEnabled = false; $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink1 = ""; $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' ); $downloadLabel1 = ""; break; } $oUser = new Users(); if (($usrId != "-1") && ($oUser->userExists( $usrId ))) { $row5 = $oUser->load( $usrId ); } else { $row5['USR_USERNAME'] = "******"; } //Labels/Links $row6 = array (); $row6['DELETE_LABEL'] = G::LoadTranslation( 'ID_DELETE' ); $row6['DOWNLOAD_LABEL'] = $downloadLabel; $row6['DOWNLOAD_LINK'] = $downloadLink; $row6['DOWNLOAD_LABEL1'] = $downloadLabel1; $row6['DOWNLOAD_LINK1'] = $downloadLink1; //if(($docVersion>1)&&($row1['APP_DOC_TYPE']!="OUTPUT")){ if (($docVersion > 1)) { $row6['VERSIONHISTORY_LABEL'] = G::LoadTranslation( 'ID_VERSION_HISTORY' ); } if ($versioningEnabled) { $row6['NEWVERSION_LABEL'] = G::LoadTranslation( 'ID_NEW_VERSION' ); } $row6['APP_DOC_UID_VERSION'] = $appDocUid . "_" . $docVersion; if ($appUid == "00000000000000000000000000000000") { //External Files $row1['APP_DOC_TYPE'] = G::LoadTranslation( 'ID_EXTERNAL_FILE' ); } //**** End get docinfo $infoMerged = array_merge( $row1, $row2, $row3, $row4, $row5, $row6 ); $sUserUID = $_SESSION['USER_LOGGED']; $aObjectPermissions = array (); if (isset( $infoMerged['PRO_UID'] )) { $aObjectPermissions = $oCase->getAllObjects( $infoMerged['PRO_UID'], $infoMerged['APP_UID'], '', $sUserUID ); } if (! is_array( $aObjectPermissions )) { $aObjectPermissions = array ('DYNAFORMS' => array (- 1), 'INPUT_DOCUMENTS' => array (- 1), 'OUTPUT_DOCUMENTS' => array (- 1) ); } if (! isset( $aObjectPermissions['DYNAFORMS'] )) { $aObjectPermissions['DYNAFORMS'] = array (- 1); } else { if (! is_array( $aObjectPermissions['DYNAFORMS'] )) { $aObjectPermissions['DYNAFORMS'] = array (- 1); } } if (! isset( $aObjectPermissions['INPUT_DOCUMENTS'] )) { $aObjectPermissions['INPUT_DOCUMENTS'] = array (- 1); } else { if (! is_array( $aObjectPermissions['INPUT_DOCUMENTS'] )) { $aObjectPermissions['INPUT_DOCUMENTS'] = array (- 1); } } if (! isset( $aObjectPermissions['OUTPUT_DOCUMENTS'] )) { $aObjectPermissions['OUTPUT_DOCUMENTS'] = array (- 1); } else { if (! is_array( $aObjectPermissions['OUTPUT_DOCUMENTS'] )) { $aObjectPermissions['OUTPUT_DOCUMENTS'] = array (- 1); } } return array_merge( $infoMerged, $aObjectPermissions ); } }
/** * @param string $n * @return bool */ public static function has($n) { return Application::exists($n); }
function authenticate($require_king = false) { $token = false; $cookie = false; $cookie_auth = isset($_SERVER['HTTP_X_KOKEN_AUTH']) && $_SERVER['HTTP_X_KOKEN_AUTH'] === 'cookie'; $this->load->helper('cookie'); if (isset($_COOKIE['koken_session_ci']) && $cookie_auth) { $token = $this->session->userdata('token'); if ($token) { $cookie = true; } } else { if (isset($_COOKIE['koken_session']) && !$this->strict_cookie_auth) { $cookie = unserialize($_COOKIE['koken_session']); $token = $cookie['token']; } else { if ($this->method == 'get' && preg_match("/token:([a-zA-Z0-9]{32})/", $this->uri->uri_string(), $matches)) { // TODO: deprecate this in favor of X-KOKEN-TOKEN $token = $matches[1]; } else { if (isset($_REQUEST['token'])) { $token = $_REQUEST['token']; } else { if (isset($_SERVER['HTTP_X_KOKEN_TOKEN'])) { $token = $_SERVER['HTTP_X_KOKEN_TOKEN']; } } } } } if ($token && $token === $this->config->item('encryption_key')) { return true; } else { if ($token) { $a = new Application(); $a->where('token', $token)->limit(1)->get(); if ($a->exists()) { if ($a->role === 'god' && $this->strict_cookie_auth) { if (!$cookie) { return false; } } else { if ($a->single_use) { $a->delete(); } } return array($a->user_id, $token, $a->role); } } else { if ($cookie_auth && get_cookie('remember_me')) { $remember_token = get_cookie('remember_me'); $u = new User(); $u->where('remember_me', $remember_token)->get(); if ($u->exists()) { $token = $u->create_session($this->session, true); return array($u->id, $token, 'god'); } } } } return false; }
/** * Validate app_uid * * @param string $app_uid, Uid for application * @param string $nameField . Name of field for message * * @access public * @author Brayan Pereyra (Cochalo) <*****@*****.**> * @copyright Colosa - Bolivia * * @return string */ public static function appUid($app_uid, $nameField = 'app_uid') { $app_uid = trim($app_uid); if ($app_uid == '') { throw new \Exception(\G::LoadTranslation("ID_APPLICATION_NOT_EXIST", array($nameField, ''))); } $oApplication = new \Application(); if (!$oApplication->exists($app_uid)) { throw new \Exception(\G::LoadTranslation("ID_APPLICATION_NOT_EXIST", array($nameField, $app_uid))); } return $app_uid; }