Example #1
0
 static function showForItemtype($type)
 {
     global $DB;
     if (!Session::haveRight("profile", "r")) {
         return false;
     }
     $canedit = Session::haveRight("profile", "w");
     echo "<form action='" . Toolbox::getItemTypeSearchURL(__CLASS__) . "' method='post'>";
     echo "<table class='tab_cadre_fixe'>";
     $itemtype = $type->fields['itemtype'];
     echo "<tr><th colspan='2' align='center'><strong>";
     echo __("Rights assignment") . ":&nbsp;";
     echo $itemtype::getTypeName();
     echo "</strong></th></tr>";
     foreach (getAllDatasFromTable('glpi_profiles') as $profile) {
         echo "<tr><th colspan='2' align='center'><strong>";
         echo __("Profile") . " " . $profile['name'] . "</strong></th></tr>";
         $go_profile = new self();
         if ($go_profile->getProfilesFromDB($profile['id'])) {
             self::createAccess($profile['id']);
             $go_profile->getProfilesFromDB($profile['id']);
         }
         $prefix = "profiles[" . $go_profile->getID() . "]";
         if ($profile['interface'] == 'central') {
             echo "<tr class='tab_bg_2'>";
             echo "<td>" . __("Access object", "genericobject") . ":</td><td>";
             Profile::dropdownNoneReadWrite($prefix . "[right]", $go_profile->fields[$type->fields['itemtype']], 1, 1, 1);
             echo "</td></tr>";
         }
         if ($type->canUseTickets()) {
             echo "<tr class='tab_bg_2'>";
             echo "<td>" . __("Associate tickets to this object", "genericobject") . ":</td><td>";
             Dropdown::showYesNo($prefix . "[open_ticket]", $go_profile->fields[$type->fields['itemtype'] . '_open_ticket']);
             echo "</td></tr>";
         }
     }
     if ($canedit) {
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center' colspan='2'>";
         echo "<input type='submit' name='update_all_rights' value=\"" . _sx('button', 'Post') . "\" class='submit'>";
         echo "</td></tr>";
     }
     echo "</table>";
     Html::closeForm();
 }
 static function transfer($ID, $entity)
 {
     global $DB;
     if ($ID > 0) {
         // Not already transfer
         // Search init item
         foreach ($DB->request('glpi_plugin_racks_racktypes', array('id' => $ID)) as $data) {
             $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);
             }
             return $newID;
         }
     }
     return 0;
 }
Example #3
0
 private static function insertTag($tag, $pid, $langid)
 {
     # Insert tagname
     $etag = GDO::escape($tag);
     $langid = (int) $langid;
     if (false === ($tid = GDO::table(__CLASS__)->selectVar('ptag_tid', "ptag_tag='{$etag}' AND ptag_lang={$langid}"))) {
         $newtag = new self(array('ptag_tid' => '0', 'ptag_lang' => $langid, 'ptag_tag' => $tag, 'ptag_count' => '1'));
         if (false === $newtag->insert()) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         if (0 == ($tid = $newtag->getID())) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     # Insert into map
     $data = array('ptm_pid' => $pid, 'ptm_tid' => $tid);
     if (false === GDO::table('GWF_PageTagMap')->insertAssoc($data, true)) {
         return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return true;
 }
Example #4
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;
 }
 static function transfer($ID, $entity)
 {
     global $DB;
     if ($ID > 0) {
         // Not already transfer
         // Search init item
         $query = "SELECT *\n                   FROM `glpi_plugin_webapplications_webapplicationtypes`\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);
                 }
                 return $newID;
             }
         }
     }
     return 0;
 }
Example #6
0
 static function transfer($ID, $entity)
 {
     global $DB;
     $phoneOperator = new self();
     if ($ID > 0) {
         // Not already transfer
         // Search init item
         $query = "SELECT *\n                   FROM `" . $phoneOperator->getTable() . "`\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;
                 $newID = $phoneOperator->getID($input);
                 if ($newID < 0) {
                     $newID = $phoneOperator->import($input);
                 }
                 return $newID;
             }
         }
     }
     return 0;
 }
Example #7
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 #8
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);
 }
Example #9
0
 /**
  * @param $networkPortID
  **/
 static function showFormForNetworkPort($networkPortID)
 {
     global $DB, $CFG_GLPI;
     $name = new self();
     $number_names = 0;
     if ($networkPortID > 0) {
         $query = "SELECT `id`\n                   FROM `" . $name->getTable() . "`\n                   WHERE `itemtype` = 'NetworkPort'\n                   AND `items_id` = '{$networkPortID}'\n                   AND `is_deleted` = '0'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 1) {
             echo "<tr class='tab_bg_1'><th colspan='4'>" . __("Several network names available! Go to the tab 'Network Name' to manage them.") . "</th></tr>\n";
             return;
         }
         switch ($DB->numrows($result)) {
             case 1:
                 $nameID = $DB->fetch_assoc($result);
                 $name->getFromDB($nameID['id']);
                 break;
             case 0:
                 $name->getEmpty();
                 break;
         }
     } else {
         $name->getEmpty();
     }
     echo "<tr class='tab_bg_1'><th colspan='4'>";
     // If the networkname is defined, we must be able to edit it. So we make a link
     if ($name->getID() > 0) {
         echo "<a href='" . $name->getLinkURL() . "'>" . self::getTypeName(1) . "</a>";
         echo "<input type='hidden' name='NetworkName_id' value='" . $name->getID() . "'>&nbsp;\n";
         Html::showSimpleForm($name->getFormURL(), 'unaffect', _sx('button', 'Dissociate'), array('id' => $name->getID()), $CFG_GLPI["root_doc"] . '/pics/sub_dropdown.png');
     } else {
         echo self::getTypeName(1);
     }
     echo "</th>\n";
     echo "</tr><tr class='tab_bg_1'>";
     echo "<td>" . self::getTypeName(1) . "</td><td>\n";
     Html::autocompletionTextField($name, "name", array('name' => 'NetworkName_name'));
     echo "</td>\n";
     echo "<td>" . FQDN::getTypeName(1) . "</td><td>";
     Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField("fqdns_id")), array('value' => $name->fields["fqdns_id"], 'name' => 'NetworkName_fqdns_id', 'entity' => $name->getEntityID(), 'displaywith' => array('view')));
     echo "</td>\n";
     echo "</tr><tr class='tab_bg_1'>\n";
     echo "<td>" . IPAddress::getTypeName(Session::getPluralNumber());
     IPAddress::showAddChildButtonForItemForm($name, 'NetworkName__ipaddresses');
     echo "</td>";
     echo "<td>";
     IPAddress::showChildsForItemForm($name, 'NetworkName__ipaddresses');
     echo "</td>";
     // MoYo : really need to display it here ?
     // make confure because not updatable
     //       echo "<td>".IPNetwork::getTypeName(Session::getPluralNumber())."&nbsp;";
     //       Html::showToolTip(__('IP network is not included in the database. However, you can see current available networks.'));
     //       echo "</td><td>";
     //       IPNetwork::showIPNetworkProperties($name->getEntityID());
     //       echo "</td>\n";
     echo "<td colspan='2'>&nbsp;</td>";
     echo "</tr>\n";
 }
 /**
  * Delete config entries
  *
  * @since version 0.85
  *
  * @param $context string  context to get values (default for glpi is core)
  * @param $values  array   of config names to delete
  *
  * @return array of config values
  **/
 static function deleteConfigurationValues($context, array $values = array())
 {
     $config = new self();
     foreach ($values as $value) {
         if ($config->getFromDBByQuery("WHERE `context` = '{$context}'\n                                              AND `name` = '{$value}'")) {
             $config->delete(array('id' => $config->getID()));
         }
     }
 }
Example #11
0
 /** Get data to display on GANTT for a project task
  *
  * @param $ID ID of the project task
  */
 static function getDataToDisplayOnGantt($ID)
 {
     global $DB;
     $todisplay = array();
     $task = new self();
     //       echo $ID.'<br>';
     if ($task->getFromDB($ID)) {
         $subtasks = array();
         foreach ($DB->request('glpi_projecttasks', array('projecttasks_id' => $ID, 'ORDER' => array('plan_start_date', 'real_start_date'))) as $data) {
             $subtasks += static::getDataToDisplayOnGantt($data['id']);
         }
         $real_begin = NULL;
         $real_end = NULL;
         // Use real if set
         if (!is_null($task->fields['real_start_date'])) {
             $real_begin = $task->fields['real_start_date'];
         }
         // Determine begin / end date of current task if not set (min/max sub projects / tasks)
         if (is_null($real_begin)) {
             if (!is_null($task->fields['plan_start_date'])) {
                 $real_begin = $task->fields['plan_start_date'];
             } else {
                 foreach ($subtasks as $subtask) {
                     if (is_null($real_begin) || !is_null($subtask['from']) && $real_begin > $subtask['from']) {
                         $real_begin = $subtask['from'];
                     }
                 }
             }
         }
         // Use real if set
         if (!is_null($task->fields['real_end_date'])) {
             $real_end = $task->fields['real_end_date'];
         }
         if (is_null($real_end)) {
             if (!is_null($task->fields['plan_end_date'])) {
                 $real_end = $task->fields['plan_end_date'];
             } else {
                 foreach ($subtasks as $subtask) {
                     if (is_null($real_end) || !is_null($subtask['to']) && $real_end < $subtask['to']) {
                         $real_end = $subtask['to'];
                     }
                 }
             }
         }
         $parents = 0;
         if ($task->fields['projecttasks_id'] > 0) {
             $parents = count(getAncestorsOf("glpi_projecttasks", $ID));
         }
         if ($task->fields['is_milestone']) {
             $percent = "";
         } else {
             $percent = isset($task->fields['percent_done']) ? $task->fields['percent_done'] : 0;
         }
         // Add current task
         $todisplay[$real_begin . '#' . $real_end . '#task' . $task->getID()] = array('id' => $task->getID(), 'name' => $task->fields['name'], 'desc' => $task->fields['content'], 'link' => $task->getlink(), 'type' => 'task', 'percent' => $percent, 'from' => $real_begin, 'parents' => $parents, 'to' => $real_end, 'is_milestone' => $task->fields['is_milestone']);
         // Add ordered subtasks
         foreach ($subtasks as $key => $val) {
             $todisplay[$key] = $val;
         }
     }
     return $todisplay;
 }
Example #12
0
 /** Get data to display on GANTT
  *
  * @param $ID        integer   ID of the project
  * @param $showall   boolean   show all sub items (projects / tasks) (true by default)
  */
 static function getDataToDisplayOnGantt($ID, $showall = true)
 {
     global $DB;
     $todisplay = array();
     $project = new self();
     if ($project->getFromDB($ID)) {
         $projects = array();
         foreach ($DB->request('glpi_projects', array('projects_id' => $ID)) as $data) {
             $projects += static::getDataToDisplayOnGantt($data['id']);
         }
         ksort($projects);
         // Get all tasks
         $tasks = ProjectTask::getAllForProject($ID);
         $real_begin = NULL;
         $real_end = NULL;
         // Use real if set
         if (is_null($project->fields['real_start_date'])) {
             $real_begin = $project->fields['real_start_date'];
         }
         // Determine begin / end date of current project if not set (min/max sub projects / tasks)
         if (is_null($real_begin)) {
             if (!is_null($project->fields['plan_start_date'])) {
                 $real_begin = $project->fields['plan_start_date'];
             } else {
                 foreach ($tasks as $task) {
                     if (is_null($real_begin) || !is_null($task['plan_start_date']) && $real_begin > $task['plan_start_date']) {
                         $real_begin = $task['plan_start_date'];
                     }
                 }
                 foreach ($projects as $p) {
                     if (is_null($real_begin) || $p['type'] == 'project' && !is_null($p['from']) && $real_begin > $p['from']) {
                         $real_begin = $p['from'];
                     }
                 }
             }
         }
         // Use real if set
         if (!is_null($project->fields['real_end_date'])) {
             $real_end = $project->fields['real_end_date'];
         }
         if (is_null($real_end)) {
             if (!is_null($project->fields['plan_end_date'])) {
                 $real_end = $project->fields['plan_end_date'];
             } else {
                 foreach ($tasks as $task) {
                     if (is_null($real_end) || !is_null($task['plan_end_date']) && $real_end < $task['plan_end_date']) {
                         $real_end = $task['plan_end_date'];
                     }
                 }
                 foreach ($projects as $p) {
                     if (is_null($real_end) || $p['type'] == 'project' && !is_null($p['to']) && $real_end < $p['to']) {
                         $real_end = $p['to'];
                     }
                 }
             }
         }
         // Add current project
         $todisplay[$real_begin . '#' . $real_end . '#project' . $project->getID()] = array('id' => $project->getID(), 'name' => $project->fields['name'], 'link' => $project->getLink(), 'desc' => $project->fields['content'], 'percent' => isset($project->fields['percent_done']) ? $project->fields['percent_done'] : 0, 'type' => 'project', 'from' => $real_begin, 'to' => $real_end);
         if ($showall) {
             // Add current tasks
             $todisplay += ProjectTask::getDataToDisplayOnGanttForProject($ID);
             // Add ordered subprojects
             foreach ($projects as $key => $val) {
                 $todisplay[$key] = $val;
             }
         }
     }
     return $todisplay;
 }
Example #13
0
 /**
  * Insert a new image.
  * @param int $uid
  * @param string $url
  * @param string $description
  * @return Dog_Link
  */
 public static function insertImage($uid, $url, $content)
 {
     $link = new self(array('link_id' => '0', 'link_uid' => $uid, 'link_url' => $url, 'link_text' => Common::substrFrom($url, '/', 'IMAGE', true), 'link_rating' => '0', 'link_date' => GWF_Time::getDate(14), 'link_type' => 'image'));
     if (false === $link->insert()) {
         echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return false;
     }
     $path = GWF_WWW_PATH . 'dbimg/dogimg/' . $link->getID();
     if (false === GWF_File::writeFile($path, $content)) {
         echo GWF_HTML::err('ERR_WRITE_FILE', array($path));
         $link->delete();
         return false;
     }
     return $link;
 }
Example #14
0
 public static function create(SR_Player $player, $name)
 {
     $clan = new self(array('sr4cl_id' => '0', 'sr4cl_name' => $name, 'sr4cl_founder' => $player->getID(), 'sr4cl_slogan' => '', 'sr4cl_date' => GWF_Time::getDate(), 'sr4cl_members' => '0', 'sr4cl_max_members' => self::MIN_MEMBERCOUNT, 'sr4cl_storage' => '0', 'sr4cl_max_storage' => self::MIN_STORAGE, 'sr4cl_money' => '0', 'sr4cl_max_money' => self::MIN_MONEY, 'sr4cl_options' => '0'));
     if (false === $clan->insert()) {
         echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return false;
     }
     if (false === $clan->join($player)) {
         echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return false;
     }
     if (false === SR_ClanMembers::setClanOptions($clan->getID(), $player->getID(), SR_ClanMembers::FOUNDER)) {
         echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return false;
     }
     if (false === SR_ClanHistory::onCreate($clan, $player)) {
         echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return false;
     }
     return $clan;
 }