Example #1
0
 /**
  * Function: authenticate
  * Checks to see if a given Login and Password match a user in the database.
  *
  * Parameters:
  *     $login - The Login to check.
  *     $password - The matching Password to check.
  *
  * Returns:
  *     @true@ or @false@
  */
 static function authenticate($login, $password)
 {
     $check = new self(array("login" => $login));
     if ($check->no_results) {
         return false;
     } else {
         if (self::checkPassword($password, $check->password)) {
             return true;
         } elseif (md5($password) == $check->password) {
             # Backwards-compatibility:
             # if their old password is stored as MD5, update
             # it on authentication to the new hashing scheme.
             $check->update(null, self::hashPassword($password));
             return true;
         } else {
             # Some imports might use MySQL password hashing (such as MovableType 3).
             # Try those too, and update the user if they match.
             $sql = SQL::current();
             $old = $sql->query("SELECT OLD_PASSWORD(:pass)", array(":pass" => $password))->fetch();
             if ($old[0] == $check->password) {
                 $check->update(null, self::hashPassword($password));
                 return true;
             }
             $new = $sql->query("SELECT PASSWORD(:pass)", array(":pass" => $password))->fetch();
             if ($new[0] == $check->password) {
                 $check->update(null, self::hashPassword($password));
                 return true;
             }
         }
     }
     return false;
 }
Example #2
0
 /**
  * Function: authenticate
  * Checks to see if a given Login and Password match a user in the database.
  *
  * Parameters:
  *     $login - The Login to check.
  *     $password - The matching Password to check.
  *
  * Returns:
  *     @true@ or @false@
  */
 static function authenticate($login, $password)
 {
     $check = new self(array("login" => $login));
     if ($check->no_results) {
         return false;
     } else {
         if (self::checkPassword($password, $check->password)) {
             return true;
         } elseif (md5($password) == $check->password) {
             # Backwards-compatibility:
             # if their old password is stored as MD5, update
             # it on authentication to the new hashing scheme.
             $check->update(null, self::hashPassword($password));
             return true;
         } elseif (SQL::current()->adapter == "mysql") {
             # Some imports might use MySQL password hashing (such as MovableType 3).
             # Try those too, and update the user if they match.
             if ($password == $check->password) {
                 $check->update(null, self::hashPassword($password));
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Import relevant properties from given exercise
  *
  * @param ilObjExercise $a_test
  * @return object
  */
 public static function createFromExercise(ilObjExercise $a_exercise, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("exercise");
     $newObj = new self();
     $newObj->setTitle($a_exercise->getTitle());
     $newObj->setDescription($a_exercise->getDescription());
     include_once "Services/Tracking/classes/class.ilLPMarks.php";
     $lp_marks = new ilLPMarks($a_exercise->getId(), $a_user_id);
     $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
     // create certificate
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
     $certificate = new ilCertificate(new ilExerciseCertificateAdapter($a_exercise));
     $certificate = $certificate->outCertificate(array("user_id" => $a_user_id), false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "exc_" . $a_exercise->getId() . "_" . $a_user_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
     // remove if certificate works
     $newObj->create();
     return $newObj;
 }
 /**
  * Import relevant properties from given test
  *
  * @param ilObjTest $a_test
  * @return object
  */
 public static function createFromTest(ilObjTest $a_test, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("wsp");
     $newObj = new self();
     $newObj->setTitle($lng->txt("wsp_type_tstv") . " \"" . $a_test->getTitle() . "\"");
     $newObj->setDescription($a_test->getDescription());
     $active_id = $a_test->getActiveIdOfUser($a_user_id);
     $pass = ilObjTest::_getResultPass($active_id);
     $date = $a_test->getPassFinishDate($active_id, $pass);
     $newObj->setProperty("issued_on", new ilDate($date, IL_CAL_UNIX));
     // create certificate
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/Test/classes/class.ilTestCertificateAdapter.php";
     $certificate = new ilCertificate(new ilTestCertificateAdapter($a_test));
     $certificate = $certificate->outCertificate(array("active_id" => $active_id, "pass" => $pass), false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "tst_" . $a_test->getId() . "_" . $a_user_id . "_" . $active_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
 }
Example #5
0
 public static function addChat($IDParent, $Type, $Tag, $Text, $IDUser = null)
 {
     $IDChat = parent::addChat($IDParent, $Text, $IDUser);
     $TheChat = new self();
     $Data = array('Tag' => $Tag, 'Type' => $Type);
     return $TheChat->update($Data, "IDChat = '{$IDChat}'");
 }
Example #6
0
 public static function modify($params)
 {
     $member = new self();
     foreach ($params as $key => $value) {
         $member->{$key} = $value;
     }
     $member->update($params);
 }
Example #7
0
 static function addRightToProfile($profiles_id, $right, $value = '')
 {
     $myProf = new self();
     if ($myProf->getFromDBByProfile($profiles_id)) {
         $tmp = $myProf->fields;
         $tmp[$right] = $value;
         $myProf->update($tmp);
     }
 }
Example #8
0
 /**
  * @param $name
  * @param $value
  */
 public static function set($name, $value)
 {
     $obj = new self($name);
     $obj->setValue($value);
     if (self::where(array('name' => $name))->hasSets()) {
         $obj->update();
     } else {
         $obj->create();
     }
 }
Example #9
0
 /**
  * Pre update consumable
  * 
  * @param ConsumableItem $consumableItem
  */
 static function preUpdateConsumable(ConsumableItem $consumableItem)
 {
     $field = new self();
     $field->getFromDBByQuery(" WHERE `consumables_id` = '" . $consumableItem->input['id'] . "'");
     if (!empty($field->fields)) {
         $field->update(array('id' => $field->fields['id'], 'order_ref' => $consumableItem->input['order_ref']));
     } else {
         self::postAddConsumable($consumableItem);
     }
 }
Example #10
0
 static function updateProfile($input)
 {
     $fields_profile = new self();
     foreach ($input['rights'] as $profiles_id => $right) {
         $found = $fields_profile->find("`profiles_id` = '{$profiles_id}'\n                         AND `plugin_fields_containers_id` = '" . $input['plugin_fields_containers_id'] . "'");
         $first_found = array_shift($found);
         $fields_profile->update(array('id' => $first_found['id'], 'profiles_id' => $profiles_id, 'plugin_fields_containers_id' => $input['plugin_fields_containers_id'], 'right' => $right));
     }
     return true;
 }
Example #11
0
 public static function replyMessage($IDParent, $Text, $Sender = null)
 {
     if (!isset($Sender)) {
         $Sender = Zend_Auth::getInstance()->getIdentity()->IDUser;
     }
     $Data = array('IDSender' => $Sender, 'Text' => $Text, 'Date' => new Zend_Db_Expr("NOW()"), 'IDParent' => $IDParent);
     $Message = new self();
     $IDMessage = $Message->insert($Data);
     if ($IDMessage) {
         $Data = array('IDLastMessage' => $IDMessage, 'DateLastMessage' => new Zend_Db_Expr("NOW()"));
         $Message->update($Data, "IDMessage = '{$IDParent}'");
     }
     return $IDMessage;
 }
Example #12
0
 /**
  * Update the property of a user or insert it if it does not exist
  *
  * @param integer $userId the id of the user
  * @param string $key the name (key) of the property
  * @param string $value the value to be set
  *
  * @return void
  */
 public function ins($userId, $key, $value)
 {
     $table = new self();
     $where = '`key` = ' . $this->_db->quote($key) . ' AND user_id = ' . $this->_db->quote($userId);
     $select = $this->_db->select('id')->from('property')->where($where);
     $stmt = $this->_db->query($select);
     $result = $stmt->fetchColumn();
     $data = array('value' => $value);
     if (false === empty($result)) {
         $table->update($data, $where);
     } else {
         $data['user_id'] = $userId;
         $data['key'] = $key;
         $table->insert($data);
     }
 }
Example #13
0
 /**
  * Function: authenticate
  * Checks to see if a given Login and Password match a user in the database.
  *
  * Parameters:
  *     $login - The Login to check.
  *     $password - The matching Password to check.
  *
  * Returns:
  *     @true@ or @false@
  */
 static function authenticate($login, $password)
 {
     $check = new self(array("login" => $login));
     if ($check->no_results) {
         return false;
     } else {
         if (self::checkPassword($password, $check->password)) {
             return true;
         } elseif (md5($password) == $check->password) {
             # Backwards-compatibility:
             # if their old password is stored as MD5, update
             # it on authentication to the new hashing scheme.
             $check->update(null, self::hashPassword($password));
             return true;
         }
     }
 }
Example #14
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case "use_filter_assign_group":
             $escalade_user = new self();
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($escalade_user->getFromDBByQuery("WHERE users_id = {$id}")) {
                     $escalade_user->fields['use_filter_assign_group'] = $input['use_filter_assign_group'];
                     if ($escalade_user->update($escalade_user->fields)) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
     }
 }
Example #15
0
 public static function refreshUser($userId, $route)
 {
     $time = time();
     $model = self::find()->where(['user_id' => $userId])->one();
     // exists $this->user_id in table?
     if (!$model) {
         // insert
         $model = new self();
         $model->last_timestamp = $time;
         $model->user_id = $userId;
         $model->invoken_route = $route;
         $model->insert();
     } else {
         $model->last_timestamp = $time;
         $model->invoken_route = $route;
         $model->update();
     }
 }
Example #16
0
 /**
  * 保存数据
  * @param array $attr
  * @param object $o
  * @return array
  */
 static function dataSave($attr, $o = false)
 {
     $return = array('status' => false, 'message' => null);
     $columnMap = null;
     if (!$o) {
         // 插入
         $o = new self();
         if ($o->create($attr) == false) {
             $return['message'] = join($o->getMessages(), '<br>');
         }
     } else {
         // 更新
         if ($o->update($attr) == false) {
             $return['message'] = join($o->getMessages(), '<br>');
         }
     }
     if (is_null($return['message'])) {
         $return['status'] = true;
     }
     return $return;
 }
Example #17
0
 public static function refreshOnline($IDUser = null, $Location = null)
 {
     if (!isset($IDUser)) {
         $IDUser = Zend_Auth::getInstance()->getIdentity()->IDUser;
     }
     $TheOnline = new self();
     $Data = array('Date' => new Zend_Db_Expr('NOW()'));
     if (isset($Location)) {
         $Data['IDLocation'] = $Location;
     }
     $Online = $TheOnline->fetchAll("IDUser = '******'");
     if ($Online->count() == 1) {
         $TheOnline->update($Data, "IDUser = '******'");
     } else {
         if ($Online->count() > 1) {
             $TheOnline->delete("IDUser = '******'");
         }
         $Data['IDUser'] = $IDUser;
         $TheOnline->insert($Data);
     }
 }
 /**
  * Import relevant properties from given learning module
  *
  * @param ilObjSAHSLearningModule $a_lm
  * @return object
  */
 public static function createFromSCORMLM(ilObjSAHSLearningModule $a_lm, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("sahs");
     $newObj = new self();
     $newObj->setTitle($a_lm->getTitle());
     $newObj->setDescription($a_lm->getDescription());
     include_once "Services/Tracking/classes/class.ilLPMarks.php";
     $lp_marks = new ilLPMarks($a_lm->getId(), $a_user_id);
     $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
     // create certificate
     if (!stristr(get_class($a_lm), "2004")) {
         $last_access = ilObjSCORMLearningModule::_lookupLastAccess($a_lm->getId(), $a_user_id);
     } else {
         $last_access = ilObjSCORM2004LearningModule::_lookupLastAccess($a_lm->getId(), $a_user_id);
     }
     $params = array("user_data" => ilObjUser::_lookupFields($a_user_id), "last_access" => $last_access);
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/ScormAicc/classes/class.ilSCORMCertificateAdapter.php";
     $certificate = new ilCertificate(new ilSCORMCertificateAdapter($a_lm));
     $certificate = $certificate->outCertificate($params, false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "sahs_" . $a_lm->getId() . "_" . $a_user_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
 }
Example #19
0
 /**
  * Get personal token of a user. If not exists generate it.
  *
  * @param $ID user ID
  *
  * @return string personal token
  **/
 static function getPersonalToken($ID)
 {
     global $DB;
     $user = new self();
     if ($user->getFromDB($ID)) {
         if (!empty($user->fields['personal_token'])) {
             return $user->fields['personal_token'];
         }
         $token = self::getUniquePersonalToken();
         $user->update(array('id' => $user->getID(), 'personal_token' => $token, 'personal_token_date' => $_SESSION['glpi_currenttime']));
         return $user->fields['personal_token'];
     }
     return false;
 }
Example #20
0
 /**
  * Update the rights of a profile (static since 0.90.1)
  *
  * @param $profiles_id
  * @param $rights         array
  */
 public static function updateProfileRights($profiles_id, array $rights = array())
 {
     $me = new self();
     foreach ($rights as $name => $right) {
         if (isset($right)) {
             if ($me->getFromDBByQuery("WHERE `profiles_id` = '{$profiles_id}'\n                                             AND `name` = '{$name}'")) {
                 $input = array('id' => $me->getID(), 'rights' => $right);
                 $me->update($input);
             } else {
                 $input = array('profiles_id' => $profiles_id, 'name' => $name, 'rights' => $right);
                 $me->add($input);
             }
         }
     }
     // Don't forget to complete the profile rights ...
     self::fillProfileRights($profiles_id);
 }
 /**
  * Update validity indicator of a specific license
  * @param $ID ID of the licence
  *
  * @since version 0.85
  *
  * @return nothing
  **/
 static function updateValidityIndicator($ID)
 {
     $lic = new self();
     if ($lic->getFromDB($ID)) {
         $valid = self::computeValidityIndicator($ID, $lic->fields['number']);
         if ($valid != $lic->fields['is_valid']) {
             $lic->update(array('id' => $ID, 'is_valid' => $valid));
         }
     }
 }
Example #22
0
 /**
  * Cron for ticket's automatic close
  *
  * @param $task : crontask object
  *
  * @return integer (0 : nothing done - 1 : done)
  **/
 static function cronCloseTicket($task)
 {
     global $DB;
     $ticket = new self();
     // Recherche des entités
     $tot = 0;
     foreach (Entity::getEntitiesToNotify('autoclose_delay') as $entity => $delay) {
         if ($delay >= 0) {
             $query = "SELECT *\n                      FROM `glpi_tickets`\n                      WHERE `entities_id` = '" . $entity . "'\n                            AND `status` = '" . self::SOLVED . "'\n                            AND `is_deleted` = 0";
             if ($delay > 0) {
                 $query .= " AND ADDDATE(`solvedate`, INTERVAL " . $delay . " DAY) < NOW()";
             }
             $nb = 0;
             foreach ($DB->request($query) as $tick) {
                 $ticket->update(array('id' => $tick['id'], 'status' => self::CLOSED, '_auto_update' => true));
                 $nb++;
             }
             if ($nb) {
                 $tot += $nb;
                 $task->addVolume($nb);
                 $task->log(Dropdown::getDropdownName('glpi_entities', $entity) . " : {$nb}");
             }
         }
     }
     return $tot > 0;
 }
Example #23
0
 /**
  * @param $networkNameID
  * @param $items_id
  * @param $itemtype
  **/
 static function affectAddress($networkNameID, $items_id, $itemtype)
 {
     global $DB;
     $networkName = new self();
     return $networkName->update(array('id' => $networkNameID, 'items_id' => $items_id, 'itemtype' => $itemtype));
 }
Example #24
0
 /**
  * Fill, if necessary, automatically some dates when status changes
  *
  * @param item          CommonDBTM object: the item whose status have changed
  * @param action_add    true if object is added, false if updated (true by default)
  *
  * @return nothing
  **/
 static function manageDateOnStatusChange(CommonDBTM $item, $action_add = true)
 {
     global $CFG_GLPI;
     $itemtype = get_class($item);
     $changes = $item->fields;
     //Autofill date on item's status change ?
     $infocom = new self();
     $infocom->getFromDB($changes['id']);
     $tmp = array('itemtype' => $itemtype, 'items_id' => $changes['id']);
     $add_or_update = false;
     //For each date that can be automatically filled
     foreach (self::getAutoManagemendDatesFields() as $date => $date_field) {
         $resp = array();
         $result = Entity::getUsedConfig($date, $changes['entities_id']);
         //Date must be filled if status corresponds to the one defined in the config
         if (preg_match('/' . self::ON_STATUS_CHANGE . '_(.*)/', $result, $values) && $values[1] == $changes['states_id']) {
             $add_or_update = true;
             $tmp[$date_field] = $_SESSION["glpi_currenttime"];
         }
     }
     //One date or more has changed
     if ($add_or_update) {
         if (!$infocom->getFromDBforDevice($itemtype, $changes['id'])) {
             $infocom->add($tmp);
         } else {
             $tmp['id'] = $infocom->fields['id'];
             $infocom->update($tmp);
         }
     }
 }
Example #25
0
 /**
  * @param $models_id
  * @param $infos        array
  **/
 static function manageInfos($models_id, $infos = array())
 {
     global $DB;
     $info = new self();
     if (isset($_POST['data']) && is_array($_POST['data']) && count($_POST['data'])) {
         foreach ($_POST['data'] as $id => $info_infos) {
             $info_infos['id'] = $id;
             //If no field selected, reset other values
             if ($info_infos['value'] == PluginDatainjectionInjectionType::NO_VALUE) {
                 $info_infos['itemtype'] = PluginDatainjectionInjectionType::NO_VALUE;
                 $info_infos['is_mandatory'] = 0;
             } else {
                 $info_infos['is_mandatory'] = isset($info_infos['is_mandatory']) ? 1 : 0;
             }
             if ($id > 0) {
                 $info->update($info_infos);
             } else {
                 $info_infos['models_id'] = $models_id;
                 unset($info_infos['id']);
                 $info->add($info_infos);
             }
         }
     }
     $info->deleteByCriteria(array('models_id' => $models_id, 'value' => PluginDatainjectionInjectionType::NO_VALUE));
 }
Example #26
0
 /**
  * During resource or employment transfer
  *
  * @static
  * @param $ID
  * @param $entity
  * @return ID|int|the
  */
 static function transfer($ID, $entity)
 {
     global $DB;
     if ($ID > 0) {
         // Not already transfer
         // Search init item
         $query = "SELECT *\n                   FROM `glpi_plugin_resources_professions`\n                   WHERE `id` = '{$ID}'";
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result)) {
                 $data = $DB->fetch_assoc($result);
                 $data = Toolbox::addslashes_deep($data);
                 $input['name'] = $data['name'];
                 $input['entities_id'] = $entity;
                 $temp = new self();
                 $newID = $temp->getID($input);
                 if ($newID < 0) {
                     $newID = $temp->import($input);
                 }
                 //transfer of the linked line
                 $line = PluginResourcesProfessionLine::transfer($temp->fields["plugin_resources_professionlines_id"], $entity);
                 if ($line > 0) {
                     $values["id"] = $newID;
                     $values["plugin_resources_professionlines_id"] = $line;
                     $temp->update($values);
                 }
                 //transfer of the linked category
                 $category = PluginResourcesProfessionCategory::transfer($temp->fields["plugin_resources_professioncategories_id"], $entity);
                 if ($category > 0) {
                     $values["id"] = $newID;
                     $values["plugin_resources_professioncategories_id"] = $category;
                     $temp->update($values);
                 }
                 return $newID;
             }
         }
     }
     return 0;
 }
Example #27
0
 public function unlinkBudget($ID)
 {
     $order = new self();
     $order->getFromDB($ID);
     $order->update(array('id' => $ID, 'budgets_id' => 0, '_unlink_budget' => 1));
 }
 /**
  * Set config values : create or update entry
  *
  * @since version 0.85
  *
  * @param $context  string context to get values (default for glpi is core)
  * @param $values   array  of config names to set
  *
  * @return array of config values
  **/
 static function setConfigurationValues($context, array $values = array())
 {
     $config = new self();
     foreach ($values as $name => $value) {
         if ($config->getFromDBByQuery("WHERE `context` = '{$context}'\n                                              AND `name` = '{$name}'")) {
             $input = array('id' => $config->getID(), 'context' => $context, 'value' => $value);
             $config->update($input);
         } else {
             $input = array('context' => $context, 'name' => $name, 'value' => $value);
             $config->add($input);
         }
     }
 }
Example #29
0
 static function methodUpdateAppliance($params, $protocol)
 {
     global $DB;
     // TODO : add more fields + factorize field translation with methodAddAppliance
     if (isset($params['help'])) {
         return array('help' => 'bool,optional', 'is_helpdesk_visible' => 'bool,optional', 'is_recursive' => 'bool,optional', 'name' => 'string,optional', 'plugin_appliances_appliancetypes_id' => 'integer,optional', 'plugin_appliances_appliancetypes_name' => 'string,optional', 'externalid' => 'string,optional', 'id' => 'string');
     }
     if (!Session::getLoginUserID()) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     if (!isset($params['id']) || !is_numeric($params['id'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER);
     }
     if (isset($params['is_helpdesk_visible']) && !is_numeric($params['is_helpdesk_visible'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'is_helpdesk_visible');
     }
     if (isset($params['is_recursive']) && !is_numeric($params['is_recursive'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'is_recursive');
     }
     $id = intval($params['id']);
     $appliance = new self();
     if (!$appliance->can($id, 'w')) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     $input = array('id' => $id);
     if (isset($params['name'])) {
         $input['name'] = addslashes($params['name']);
     }
     if (isset($params['externalid'])) {
         if (empty($params['externalid'])) {
             $input['externalid'] = 'NULL';
         } else {
             $input['externalid'] = addslashes($params['externalid']);
         }
     }
     // Old field name for compatibility
     if (isset($params['notes'])) {
         $input['notepad'] = addslashes($params['notes']);
     }
     foreach (array('comment', 'notepad', 'serial', 'otherserial') as $field) {
         if (isset($params[$field])) {
             $input[$field] = addslashes($params[$field]);
         }
     }
     if (isset($params['is_helpdesk_visible'])) {
         $input['is_helpdesk_visible'] = $params['is_helpdesk_visible'] ? 1 : 0;
     }
     if (isset($params['is_recursive'])) {
         $input['is_recursive'] = $params['is_recursive'] ? 1 : 0;
     }
     if (isset($params['plugin_appliances_appliancetypes_name'])) {
         $type = new PluginAppliancesApplianceType();
         $input2 = array();
         $input2['entities_id'] = isset($input['entities_id']) ? $input['entities_id'] : $appliance->fields['entities_id'];
         $input2['is_recursive'] = isset($input['is_recursive']) ? $input['is_recursive'] : $appliance->fields['entities_id'];
         $input2['name'] = addslashes($params['plugin_appliances_appliancetypes_name']);
         $input['plugin_appliances_appliancetypes_id'] = $type->import($input2);
     } else {
         if (isset($params['plugin_appliances_appliancetypes_id'])) {
             $input['plugin_appliances_appliancetypes_id'] = intval($params['plugin_appliances_appliancetypes_id']);
         }
     }
     if ($appliance->update($input)) {
         // Does not detect unicity error on externalid :(
         return $appliance->methodGetAppliance(array('id' => $id), $protocol);
     }
     return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED);
 }
Example #30
0
 public static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     $config = new self();
     //This class is available since version 1.3.0
     if (!TableExists($table) && !TableExists("glpi_plugin_order_config")) {
         $migration->displayMessage("Installing {$table}");
         //Install
         $query = "CREATE TABLE `{$table}` (\n                        `id` int(11) NOT NULL auto_increment,\n                        `use_validation` tinyint(1) NOT NULL default '0',\n                        `use_supplier_satisfaction` tinyint(1) NOT NULL default '0',\n                        `use_supplier_informations` tinyint(1) NOT NULL default '0',\n                        `use_supplier_infos` tinyint(1) NOT NULL default '1',\n                        `generate_order_pdf` tinyint(1) NOT NULL default '0',\n                        `copy_documents` tinyint(1) NOT NULL default '0',\n                        `default_taxes` int(11) NOT NULL default '0',\n                        `generate_assets` int(11) NOT NULL default '0',\n                        `generated_name` varchar(255) collate utf8_unicode_ci default NULL,\n                        `generated_serial` varchar(255) collate utf8_unicode_ci default NULL,\n                        `generated_otherserial` varchar(255) collate utf8_unicode_ci default NULL,\n                        `default_asset_states_id` int(11) NOT NULL default '0',\n                        `tickettemplates_id_delivery` int(11) NOT NULL default '0',\n                        `order_status_draft` int(11) NOT NULL default '0',\n                        `order_status_waiting_approval` int(11) NOT NULL default '0',\n                        `order_status_approved` int(11) NOT NULL default '0',\n                        `order_status_partially_delivred` int(11) NOT NULL default '0',\n                        `order_status_completly_delivered` int(11) NOT NULL default '0',\n                        `order_status_canceled` int(11) NOT NULL default '0',\n                        `order_status_paid` int(11) NOT NULL default '0',\n                        `shoudbedelivered_color` char(20) collate utf8_unicode_ci default '#ff5555',\n                        `documentcategories_id` int(11) NOT NULL default '0',\n                        `groups_id_author` int(11) NOT NULL default '0',\n                        `groups_id_recipient` int(11) NOT NULL default '0',\n                        `users_id_recipient` int(11) NOT NULL default '0',\n                        `add_location` tinyint(1) NOT NULL default '0',\n                        `add_bill_details` tinyint(1) NOT NULL default '0',\n                        `hide_inactive_budgets` tinyint(1) NOT NULL default '0',\n                        `rename_documents` tinyint(1) NOT NULL default '0',\n                        `transmit_budget_change` tinyint(1) NOT NULL default '0',\n                        PRIMARY KEY  (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
         $tobefilled = "TOBEFILLED";
         $tmp = array('id' => 1, 'use_validation' => 0, 'default_taxes' => 0, 'generate_assets' => 0, 'generated_name' => $tobefilled, 'generated_serial' => $tobefilled, 'generated_otherserial' => $tobefilled, 'default_asset_states_id' => 0, 'generated_title' => $tobefilled, 'generated_content' => $tobefilled, 'default_ticketcategories_id' => 0, 'shoudbedelivered_color' => '#ff5555');
         $config->add($tmp);
     } else {
         //Upgrade
         $migration->displayMessage("Upgrading {$table}");
         //1.2.0
         $migration->renameTable("glpi_plugin_order_config", $table);
         if (!countElementsInTable("glpi_plugin_order_configs")) {
             $query = "INSERT INTO `glpi_plugin_order_configs`(`id`,`use_validation`,`default_taxes`) VALUES (1,0,0);";
             $DB->query($query) or die($DB->error());
         }
         $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment");
         //1.3.0
         $migration->addField($table, "generate_assets", "tinyint(1) NOT NULL default '0'");
         $migration->addField($table, "generated_name", "varchar(255) collate utf8_unicode_ci default NULL");
         $migration->addField($table, "generated_serial", "varchar(255) collate utf8_unicode_ci default NULL");
         $migration->addField($table, "generated_otherserial", "varchar(255) collate utf8_unicode_ci default NULL");
         $migration->addField($table, "default_asset_entities_id", "int(11) NOT NULL default '0'");
         $migration->addField($table, "default_asset_states_id", "int(11) NOT NULL default '0'");
         $migration->addField($table, "generated_title", "varchar(255) collate utf8_unicode_ci default NULL");
         $migration->addField($table, "generated_content", "text collate utf8_unicode_ci");
         $migration->addField($table, "default_ticketcategories_id", "int(11) NOT NULL default '0'");
         $migration->addField($table, "use_supplier_satisfaction", "tinyint(1) NOT NULL default '0'");
         $migration->addField($table, "generate_order_pdf", "tinyint(1) NOT NULL default '0'");
         $migration->addField($table, "use_supplier_informations", "tinyint(1) NOT NULL default '1'");
         $migration->addField($table, "shoudbedelivered_color", "char(20) collate utf8_unicode_ci default '#ff5555'");
         $migration->addField($table, "copy_documents", "tinyint(1) NOT NULL DEFAULT '0'");
         $migration->addField($table, "documentcategories_id", "integer");
         $migration->addField($table, "groups_id_author", "integer");
         $migration->addField($table, "groups_id_recipient", "integer");
         $migration->addField($table, "users_id_recipient", "integer");
         $migration->changeField($table, "default_ticketcategories_id", "default_itilcategories_id", "integer");
         //1.9.0
         $migration->addField($table, "add_location", "TINYINT(1) NOT NULL DEFAULT '0'");
         $migration->addField($table, "add_bill_details", "TINYINT(1) NOT NULL DEFAULT '0'");
         $config = new self();
         $config->getFromDB(1);
         $templateID = false;
         $migration->addField($table, "tickettemplates_id_delivery", 'integer');
         $migration->migrationOneTable($table);
         $migration->dropField($table, "generated_title");
         $migration->dropField($table, "generated_content");
         $migration->dropField($table, "default_itilcategories_id");
         $migration->addField($table, "hide_inactive_budgets", "bool");
         $migration->addField($table, "rename_documents", "bool");
         //0.85+1.2
         $migration->addField($table, "transmit_budget_change", "bool");
         $migration->migrationOneTable($table);
         if ($templateID) {
             $config->update(array('id' => 1, 'tickettemplates_id_delivery' => $templateID));
         }
     }
     $migration->displayMessage("Add default order state workflow");
     $new_states = array('order_status_draft' => 1, 'order_status_waiting_approval' => 2, 'order_status_approved' => 3, 'order_status_partially_delivred' => 4, 'order_status_completly_delivered' => 5, 'order_status_canceled' => 6, 'order_status_paid' => 7);
     foreach ($new_states as $field => $value) {
         $migration->addField($table, $field, "int(11) NOT NULL default '0'");
     }
     $migration->migrationOneTable($table);
     $new_states['id'] = 1;
     $config->update($new_states);
 }