Exemple #1
0
    /**

     * Update User

     *

     * @param string $userUid       Unique id of User

     * @param array  $arrayData     Data

     * @param string $userUidLogged Unique id of User logged

     *

     * return array Return data of the User updated

     */

    public function update($userUid, array $arrayData, $userUidLogged)

    {

        try {

            \G::LoadSystem("rbac");



            //Verify data

            $process = new \ProcessMaker\BusinessModel\Process();

            $validator = new \ProcessMaker\BusinessModel\Validator();



            $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");

            $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");



            //Set data

            $arrayData = array_change_key_case($arrayData, CASE_UPPER);

            $arrayDataBackup = $arrayData;



            //Verify data

            $this->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["usrUid"]);



            $this->throwExceptionIfDataIsInvalid($userUid, $arrayData);



            //Permission Admin

            $countPermission = 0;



            $permission = $this->loadUserRolePermission("PROCESSMAKER", $userUidLogged);



            foreach ($permission as $key => $value) {

                if ($value["PER_CODE"] == "PM_USERS") {

                    $countPermission = $countPermission + 1;

                }

            }



            if ($countPermission != 1) {

                throw new \Exception(\G::LoadTranslation("ID_USER_CAN_NOT_UPDATE", array($userUidLogged)));

            }



            //Update

            $cnn = \Propel::getConnection("workflow");



            try {

                $rbac = new \RBAC();

                $user = new \Users();



                $rbac->initRBAC();



                if (isset($arrayData["USR_NEW_PASS"])) {

                    $arrayData["USR_PASSWORD"] = \Bootstrap::hashPassword($arrayData["USR_NEW_PASS"]);

                }



                $arrayData["USR_UID"]              = $userUid;

                $arrayData["USR_LOGGED_NEXT_TIME"] = (isset($arrayData["USR_LOGGED_NEXT_TIME"]))? $arrayData["USR_LOGGED_NEXT_TIME"] : 0;

                $arrayData["USR_UPDATE_DATE"]      = date("Y-m-d H:i:s");



                $flagUserLoggedNextTime = false;



                if (isset($arrayData["USR_PASSWORD"])) {

                    if ($arrayData["USR_PASSWORD"] != "") {

                        //require_once 'classes/model/UsersProperties.php';



                        $userProperty = new \UsersProperties();

                        $aUserProperty = $userProperty->loadOrCreateIfNotExists($userUid, array("USR_PASSWORD_HISTORY" => serialize(array(\Bootstrap::hashPassword($arrayData["USR_PASSWORD"])))));



                        $memKey = "rbacSession" . session_id();

                        $memcache = & \PMmemcached::getSingleton(defined("SYS_SYS")? SYS_SYS : "");



                        if (($rbac->aUserInfo = $memcache->get($memKey)) == false) {

                            $rbac->loadUserRolePermission("PROCESSMAKER", $userUidLogged);

                            $memcache->set($memKey, $rbac->aUserInfo, \PMmemcached::EIGHT_HOURS);

                        }



                        if ($rbac->aUserInfo["PROCESSMAKER"]["ROLE"]["ROL_CODE"] == "PROCESSMAKER_ADMIN") {

                            $aUserProperty["USR_LAST_UPDATE_DATE"] = date("Y-m-d H:i:s");

                            $aUserProperty["USR_LOGGED_NEXT_TIME"] = $arrayData["USR_LOGGED_NEXT_TIME"];

                            $userProperty->update($aUserProperty);

                        }



                        $aHistory = unserialize($aUserProperty["USR_PASSWORD_HISTORY"]);



                        if (!is_array($aHistory)) {

                            $aHistory = array();

                        }



                        if (!defined("PPP_PASSWORD_HISTORY")) {

                            define("PPP_PASSWORD_HISTORY", 0);

                        }



                        if (PPP_PASSWORD_HISTORY > 0) {

                            //it's looking a password igual into aHistory array that was send for post in md5 way

                            $c = 0;

                            $sw = 1;



                            while (count($aHistory) >= 1 && count($aHistory) > $c && $sw) {

                                if (strcmp(trim($aHistory[$c]), trim($arrayData['USR_PASSWORD'])) == 0) {

                                    $sw = 0;

                                }



                                $c++;

                            }



                            if ($sw == 0) {

                                $sDescription = G::LoadTranslation("ID_POLICY_ALERT") . ":\n\n";

                                $sDescription = $sDescription . " - " . G::LoadTranslation("PASSWORD_HISTORY") . ": " . PPP_PASSWORD_HISTORY . "\n";

                                $sDescription = $sDescription . "\n" . G::LoadTranslation("ID_PLEASE_CHANGE_PASSWORD_POLICY") . "";



                                throw new \Exception($this->arrayFieldNameForException["usrNewPass"] . ": " . $sDescription);

                            }



                            if (count($aHistory) >= PPP_PASSWORD_HISTORY) {

                                $sLastPassw = array_shift($aHistory);

                            }



                            $aHistory[] = $arrayData["USR_PASSWORD"];

                        }



                        $aUserProperty["USR_LAST_UPDATE_DATE"] = date("Y-m-d H:i:s");

                        $aUserProperty["USR_LOGGED_NEXT_TIME"] = $arrayData["USR_LOGGED_NEXT_TIME"];

                        $aUserProperty["USR_PASSWORD_HISTORY"] = serialize($aHistory);

                        $userProperty->update($aUserProperty);

                    } else {

                        $flagUserLoggedNextTime = true;

                    }

                } else {

                    $flagUserLoggedNextTime = true;

                }



                if ($flagUserLoggedNextTime) {

                    //require_once "classes/model/Users.php";

                    $oUser = new \Users();

                    $aUser = $oUser->load($userUid);

                    //require_once "classes/model/UsersProperties.php";

                    $oUserProperty = new \UsersProperties();

                    $aUserProperty = $oUserProperty->loadOrCreateIfNotExists($userUid, array("USR_PASSWORD_HISTORY" => serialize(array($aUser["USR_PASSWORD"]))));

                    $aUserProperty["USR_LOGGED_NEXT_TIME"] = $arrayData["USR_LOGGED_NEXT_TIME"];

                    $oUserProperty->update($aUserProperty);

                }



                //Update in rbac

                if (isset($arrayData["USR_ROLE"])) {

                    $rbac->updateUser($arrayData, $arrayData["USR_ROLE"]);

                } else {

                    $rbac->updateUser($arrayData);

                }



                //Update in workflow

                $result = $user->update($arrayData);



                //Save Calendar assigment

                if (isset($arrayData["USR_CALENDAR"])) {

                    //Save Calendar ID for this user

                    \G::LoadClass("calendar");



                    $calendar = new \Calendar();

                    $calendar->assignCalendarTo($userUid, $arrayData["USR_CALENDAR"], "USER");

                }



                //Return

                $arrayData = $arrayDataBackup;



                if (!$this->formatFieldNameInUppercase) {

                    $arrayData = array_change_key_case($arrayData, CASE_LOWER);

                }



                return $arrayData;

            } catch (\Exception $e) {

                $cnn->rollback();



                throw $e;

            }

        } catch (\Exception $e) {

            throw $e;

        }

    }
Exemple #2
0
 /**
  * Get all properties of an Task
  * @var string $prj_uid. Uid for Process
  * @var string $act_uid. Uid for Activity
  * @var boolean $keyCaseToLower. Flag for case lower
  *
  * return object
  */
 public function getProperties($prj_uid, $act_uid, $keyCaseToLower = false, $groupData = true)
 {
     try {
         $prj_uid = $this->validateProUid($prj_uid);
         $taskUid = $this->validateActUid($act_uid);
         //G::LoadClass("configuration");
         require_once PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.configuration.php";
         $task = new \Task();
         $arrayDataAux = $task->load($taskUid);
         //$arrayDataAux["INDEX"] = 0;
         //$arrayDataAux["IFORM"] = 1;
         //$arrayDataAux["LANG"] = SYS_LANG;
         //Assignment rules
         if ($arrayDataAux["TAS_ASSIGN_TYPE"] == "SELF_SERVICE") {
             $arrayDataAux["TAS_ASSIGN_TYPE"] = !empty($arrayDataAux["TAS_GROUP_VARIABLE"]) ? "SELF_SERVICE_EVALUATE" : $arrayDataAux["TAS_ASSIGN_TYPE"];
         }
         //Timing control
         //Load Calendar Information
         $calendar = new \Calendar();
         $calendarInfo = $calendar->getCalendarFor("", "", $taskUid);
         //If the function returns a DEFAULT calendar it means that this object doesn"t have assigned any calendar
         $arrayDataAux["TAS_CALENDAR"] = $calendarInfo["CALENDAR_APPLIED"] != "DEFAULT" ? $calendarInfo["CALENDAR_UID"] : "";
         //Notifications
         $conf = new \Configurations();
         $conf->loadConfig($x, "TAS_EXTRA_PROPERTIES", $taskUid, "", "");
         $arrayDataAux["TAS_DEF_MESSAGE_TYPE"] = "text";
         $arrayDataAux["TAS_DEF_MESSAGE_TEMPLATE"] = "alert_message.html";
         if (isset($conf->aConfig["TAS_DEF_MESSAGE_TYPE"]) && isset($conf->aConfig["TAS_DEF_MESSAGE_TYPE"])) {
             $arrayDataAux["TAS_DEF_MESSAGE_TYPE"] = $conf->aConfig["TAS_DEF_MESSAGE_TYPE"];
             $arrayDataAux["TAS_DEF_MESSAGE_TEMPLATE"] = $conf->aConfig["TAS_DEF_MESSAGE_TEMPLATE"];
         }
         //Set data
         $arrayData = array();
         $keyCase = $keyCaseToLower ? CASE_LOWER : CASE_UPPER;
         if (!$groupData) {
             $arrayData = array_change_key_case($arrayDataAux, $keyCase);
             return $arrayData;
         }
         //Definition
         $arrayData["DEFINITION"] = array_change_key_case(array("TAS_PRIORITY_VARIABLE" => $arrayDataAux["TAS_PRIORITY_VARIABLE"], "TAS_DERIVATION_SCREEN_TPL" => $arrayDataAux["TAS_DERIVATION_SCREEN_TPL"]), $keyCase);
         //Assignment Rules
         $arrayData["ASSIGNMENT_RULES"] = array_change_key_case(array("TAS_ASSIGN_TYPE" => $arrayDataAux["TAS_ASSIGN_TYPE"], "TAS_ASSIGN_VARIABLE" => $arrayDataAux["TAS_ASSIGN_VARIABLE"], "TAS_GROUP_VARIABLE" => $arrayDataAux["TAS_GROUP_VARIABLE"], "TAS_SELFSERVICE_TIMEOUT" => $arrayDataAux["TAS_SELFSERVICE_TIMEOUT"], "TAS_SELFSERVICE_TIME" => $arrayDataAux["TAS_SELFSERVICE_TIME"], "TAS_SELFSERVICE_TIME_UNIT" => $arrayDataAux["TAS_SELFSERVICE_TIME_UNIT"], "TAS_SELFSERVICE_TRIGGER_UID" => $arrayDataAux["TAS_SELFSERVICE_TRIGGER_UID"], "TAS_SELFSERVICE_EXECUTION" => $arrayDataAux["TAS_SELFSERVICE_EXECUTION"]), $keyCase);
         //Timing control
         $arrayData["TIMING_CONTROL"] = array_change_key_case(array("TAS_TRANSFER_FLY" => $arrayDataAux["TAS_TRANSFER_FLY"], "TAS_DURATION" => $arrayDataAux["TAS_DURATION"], "TAS_TIMEUNIT" => $arrayDataAux["TAS_TIMEUNIT"], "TAS_TYPE_DAY" => $arrayDataAux["TAS_TYPE_DAY"], "TAS_CALENDAR" => $arrayDataAux["TAS_CALENDAR"]), $keyCase);
         //Permissions
         $arrayData["PERMISSIONS"] = array_change_key_case(array("TAS_TYPE" => $arrayDataAux["TAS_TYPE"]), $keyCase);
         //Case Labels
         $arrayData["CASE_LABELS"] = array_change_key_case(array("TAS_DEF_TITLE" => $arrayDataAux["TAS_DEF_TITLE"], "TAS_DEF_DESCRIPTION" => $arrayDataAux["TAS_DEF_DESCRIPTION"]), $keyCase);
         //Notifications
         $arrayData["NOTIFICATIONS"] = array_change_key_case(array("SEND_EMAIL" => $arrayDataAux["TAS_SEND_LAST_EMAIL"], "TAS_DEF_SUBJECT_MESSAGE" => $arrayDataAux["TAS_DEF_SUBJECT_MESSAGE"], "TAS_DEF_MESSAGE_TYPE" => $arrayDataAux["TAS_DEF_MESSAGE_TYPE"], "TAS_DEF_MESSAGE" => $arrayDataAux["TAS_DEF_MESSAGE"], "TAS_DEF_MESSAGE_TEMPLATE" => $arrayDataAux["TAS_DEF_MESSAGE_TEMPLATE"]), $keyCase);
         $arrayData = array_change_key_case($arrayData, $keyCase);
         return $arrayData;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemple #3
0
    /**
     * Create/Update Process
     *
     * @param string $option
     * @param array  $arrayDefineProcessData
     *
     * return array  Return data array with new UID for each element
     *
     * @access public
     */
    public function defineProcess($option, $arrayDefineProcessData)
    {
        if (!isset($arrayDefineProcessData["process"]) || count($arrayDefineProcessData["process"]) == 0) {
            throw (new \Exception("Process data do not exist"));
        }

        //Process
        $process = new \Process();

        $arrayProcessData = $arrayDefineProcessData["process"];

        unset($arrayProcessData["tasks"]);
        unset($arrayProcessData["routes"]);

        switch ($option) {
            case "CREATE":
                if (!isset($arrayProcessData["USR_UID"]) || trim($arrayProcessData["USR_UID"]) == "") {
                    throw (new \Exception("User data do not exist"));
                }

                if (!isset($arrayProcessData["PRO_TITLE"]) || trim($arrayProcessData["PRO_TITLE"]) == "") {
                    throw (new \Exception("Process title data do not exist"));
                }

                if (!isset($arrayProcessData["PRO_DESCRIPTION"])) {
                    throw (new \Exception("Process description data do not exist"));
                }

                if (!isset($arrayProcessData["PRO_CATEGORY"])) {
                    throw (new \Exception("Process category data do not exist"));
                }
                break;
            case "UPDATE":
                break;
        }

        if (isset($arrayProcessData["PRO_TITLE"])) {
            $arrayProcessData["PRO_TITLE"] = trim($arrayProcessData["PRO_TITLE"]);
        }

        if (isset($arrayProcessData["PRO_DESCRIPTION"])) {
            $arrayProcessData["PRO_DESCRIPTION"] = trim($arrayProcessData["PRO_DESCRIPTION"]);
        }

        if (isset($arrayProcessData["PRO_TITLE"]) && $process->existsByProTitle($arrayProcessData["PRO_TITLE"])) {
            throw (new \Exception(\G::LoadTranslation("ID_PROCESSTITLE_ALREADY_EXISTS", SYS_LANG, array("PRO_TITLE" => $arrayProcessData["PRO_TITLE"]))));
        }

        $arrayProcessData["PRO_DYNAFORMS"] = array ();
        $arrayProcessData["PRO_DYNAFORMS"]["PROCESS"] = (isset($arrayProcessData["PRO_SUMMARY_DYNAFORM"]))? $arrayProcessData["PRO_SUMMARY_DYNAFORM"] : "";

        unset($arrayProcessData["PRO_SUMMARY_DYNAFORM"]);

        switch ($option) {
            case "CREATE":
                $processUid = $process->create($arrayProcessData, false);

                //Call plugins
                //$arrayData = array(
                //    "PRO_UID"      => $processUid,
                //    "PRO_TEMPLATE" => (isset($arrayProcessData["PRO_TEMPLATE"]) && $arrayProcessData["PRO_TEMPLATE"] != "")? $arrayProcessData["PRO_TEMPLATE"] : "",
                //    "PROCESSMAP"   => $this //?
                //);
                //
                //$oPluginRegistry = &PMPluginRegistry::getSingleton();
                //$oPluginRegistry->executeTriggers(PM_NEW_PROCESS_SAVE, $arrayData);
                break;
            case "UPDATE":
                $result = $process->update($arrayProcessData);

                $processUid = $arrayProcessData["PRO_UID"];
                break;
        }

        //Process - Save Calendar ID for this process
        if (isset($arrayProcessData["PRO_CALENDAR"]) && $arrayProcessData["PRO_CALENDAR"] != "") {
            $calendar = new \Calendar();
            $calendar->assignCalendarTo($processUid, $arrayProcessData["PRO_CALENDAR"], "PROCESS");
        }

        $uidAux = $arrayDefineProcessData["process"]["PRO_UID"];
        $arrayDefineProcessData["process"]["PRO_UID"] = $processUid;
        $arrayDefineProcessData["process"]["PRO_UID_OLD"] = $uidAux;

        //Tasks
        if (isset($arrayDefineProcessData["process"]["tasks"]) && count($arrayDefineProcessData["process"]["tasks"]) > 0) {
            $arrayTaskData = $arrayDefineProcessData["process"]["tasks"];

            foreach ($arrayTaskData as $index => $value) {
                $t = $value;
                $t["PRO_UID"] = $processUid;

                $arrayData = $t;

                $action = $arrayData["_action"];

                unset($arrayData["_action"]);

                switch ($action) {
                    case "CREATE":
                        //Create task
                        $arrayDataAux = array(
                            "TAS_UID"   => $arrayData["TAS_UID"],
                            "PRO_UID"   => $arrayData["PRO_UID"],
                            "TAS_TITLE" => $arrayData["TAS_TITLE"],
                            "TAS_DESCRIPTION" => $arrayData["TAS_DESCRIPTION"],
                            "TAS_POSX"  => $arrayData["TAS_POSX"],
                            "TAS_POSY"  => $arrayData["TAS_POSY"],
                            "TAS_START" => $arrayData["TAS_START"]
                        );

                        $task = new \Task();

                        $taskUid = $task->create($arrayDataAux, false);

                        $uidAux = $arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID"];
                        $arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID"] = $taskUid;
                        $arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID_OLD"] = $uidAux;

                        //Update task properties
                        $task2 = new \ProcessMaker\BusinessModel\Task();

                        $arrayResult = $task2->updateProperties($taskUid, $processUid, $arrayData);

                        //Update array routes
                        if (isset($arrayDefineProcessData["process"]["routes"]) && count($arrayDefineProcessData["process"]["routes"]) > 0) {
                            $arrayDefineProcessData["process"]["routes"] = $this->routeUpdateTaskUidInArray($arrayDefineProcessData["process"]["routes"], $taskUid, $t["TAS_UID"]);
                        }
                        break;
                    case "UPDATE":
                        //Update task
                        $task = new \Task();

                        $result = $task->update($arrayData);

                        //Update task properties
                        $task2 = new \ProcessMaker\BusinessModel\Task();

                        $arrayResult = $task2->updateProperties($arrayData["TAS_UID"], $processUid, $arrayData);
                        break;
                    case "DELETE":
                        $tasks = new \Tasks();

                        $tasks->deleteTask($arrayData["TAS_UID"]);
                        break;
                }
            }
        }

        //Routes
        if (isset($arrayDefineProcessData["process"]["routes"]) && count($arrayDefineProcessData["process"]["routes"]) > 0) {
            $arrayRouteData = $arrayDefineProcessData["process"]["routes"];

            foreach ($arrayRouteData as $index => $value) {
                $r = $value;

                $routeUid = $this->defineRoute( //***** New method
                    $processUid,
                    $r["TAS_UID"],
                    $r["ROU_NEXT_TASK"],
                    $r["ROU_TYPE"],
                    false
                );

                $uidAux = $arrayDefineProcessData["process"]["routes"][$index]["ROU_UID"];
                $arrayDefineProcessData["process"]["routes"][$index]["ROU_UID"] = $routeUid;
                $arrayDefineProcessData["process"]["routes"][$index]["ROU_UID_OLD"] = $uidAux;
            }
        }

        return $arrayDefineProcessData;
    }