patch0.85-entity.patch

tsmr, 07/03/2013 09:46 AM

Download (14.3 KB)

View differences:

ajax/getDropdownValue.php (working copy)
99 99
}
100 100
$LIMIT = "LIMIT $start,$limit";
101 101

  
102

  
103
$where .=" AND `$table`.`id` NOT IN ('".$_GET['value']."'";
104

  
102
// Entity UPGRADE
103
$used = array();
105 104
if (isset($_GET['used'])) {
106 105
   $used = $_GET['used'];
107

  
108
   if (count($used)) {
109
      $where .= ",'".implode("','",$used)."'";
110
   }
111 106
}
107
if(!empty($_GET['value'])){
108
   array_push($used, $_GET['value']);
109
}
110
if(count($used)){
111
   $where .=" AND `$table`.`id` NOT IN ('".implode("','",$used)."') ";
112
}
113
// Entity UPGRADE
112 114

  
113 115
if (isset($_GET['toadd'])) {
114 116
   $toadd = $_GET['toadd'];
......
116 118
   $toadd = array();
117 119
}
118 120

  
119
$where .= ") ";
120

  
121 121
if (isset($_GET['condition']) && ($_GET['condition'] != '')) {
122 122
   $where .= " AND ".$_GET['condition']." ";
123 123
}
inc/dropdown.class.php (working copy)
84 84

  
85 85
      $params['name']                 = $item->getForeignKeyField();
86 86
      $params['value']                = (($itemtype == 'Entity') ? $_SESSION['glpiactive_entity'] : '');
87
      $params['value']                = (($itemtype == 'Entity' && isset($options['check_ticket_edition_on_parent'])) ? -1 : $params['value']);// Entity UPGRADE
87 88
      $params['comments']             = true;
88 89
      $params['entity']               = -1;
89 90
      $params['entity_sons']          = false;
inc/entity.class.php (working copy)
95 95
                                          => array('calendars_id', 'tickettype', 'auto_assign_mode',
96 96
                                                   'autoclose_delay', 'inquest_config',
97 97
                                                   'inquest_rate', 'inquest_delay', 'inquest_URL',
98
                                                   'max_closedate', 'tickettemplates_id'));
98
                                                   'max_closedate', 'tickettemplates_id', 'ticket_edition_on_parent'));// Entity UPGRADE
99 99

  
100 100

  
101 101
   function getForbiddenStandardMassiveAction() {
......
1803 1803
         echo "</font>";
1804 1804
      }
1805 1805
      echo "</td></tr>";
1806
      
1807
      // Entity UPGRADE
1808
      // Enables ticket edition on parent entities
1809
      if ((count(getSonsOf('glpi_entities', $ID)) > 1 || $ID == 0)) {
1810
         echo "<tr class='tab_bg_1'><td  colspan='2'>".__('Enable ticket edition')."</td>";
1811
         echo "<td colspan='2'>";
1806 1812

  
1813
         $ticket_edition_on_parent = array(
1814
             self::CONFIG_PARENT => __('Inheritance of the parent entity'), 
1815
             0 => __('No'), 
1816
             1 => __('Yes'));
1817

  
1818
         if ($ID == 0) {
1819
            unset($ticket_edition_on_parent[self::CONFIG_PARENT]);
1820
         }
1821

  
1822
         Dropdown::showFromArray('ticket_edition_on_parent',
1823
                 $ticket_edition_on_parent, 
1824
                 array('value' => $entity->fields["ticket_edition_on_parent"]));
1825

  
1826
         if (($entity->fields['ticket_edition_on_parent'] == self::CONFIG_PARENT)
1827
             && ($ID != 0)) {
1828
            $ticket_edition_on_parent = self::getUsedConfig('ticket_edition_on_parent', $entity->fields['entities_id']);
1829
            echo "<font class='green'>&nbsp;&nbsp;";
1830
            echo Dropdown::getYesNo($ticket_edition_on_parent);
1831
            echo "</font>";
1832
         }
1833
         echo "</td></tr>";
1834
      } else {// Child entity are always allowed to create ticket
1835
         echo "<input type='hidden' name='ticket_edition_on_parent' value='1' />";
1836
      }
1837
      // Entity UPGRADE
1838

  
1807 1839
      echo "<tr><th colspan='4'>".__('Automatic closing configuration')."</th></tr>";
1808 1840

  
1809 1841
      echo "<tr class='tab_bg_1'>".
inc/mailcollector.class.php (working copy)
419 419
         if ($this->getFromDB($mailcollector_id)) {
420 420
            $this->mid          = -1;
421 421
            $this->fetch_emails = 0;
422
            $error = array();// Entity UPGRADE
422 423
            //Connect to the Mail Box
423 424
            $this->connect();
424 425
            // Get Total Number of Unread Email in mail box
......
433 434
                                                         'play_rules'   => false));
434 435
                     $tkt['_users_id_requester'] = $rejected[$head['message_id']]['users_id'];
435 436
                     $tkt['entities_id']         = $entity;
436
                     $ticket->add($tkt);
437
                     // Entity UPGRADE
438
                     if(!$ticket->add($tkt)){
439
                        $error[] = 1;
440
                     }
441
                     // Entity UPGRADE
437 442
                     $folder = self::ACCEPTED_FOLDER;
438 443
                  } else {
439 444
                     $folder = self::REFUSED_FOLDER;
440 445
                  }
441
                  //Delete email
442
                  if ($this->deleteMails($i, $folder)) {
443
                     $rejectedmail = new NotImportedEmail();
444
                     $rejectedmail->delete(array('id' => $rejected[$head['message_id']]['id']));
446
                  if(in_array(1, $error)){// Entity UPGRADE
447
                     //Delete email
448
                     if ($this->deleteMails($i, $folder)) {
449
                        $rejectedmail = new NotImportedEmail();
450
                        $rejectedmail->delete(array('id' => $rejected[$head['message_id']]['id']));
451
                     }
452
                     // Unset managed
453
                     unset($rejected[$head['message_id']]);
445 454
                  }
446
                  // Unset managed
447
                  unset($rejected[$head['message_id']]);
448 455
               }
449 456
            }
450 457

  
451
            // Email not present in mailbox
452
            if (count($rejected)) {
453
               $clean = array('<' => '',
454
                              '>' => '');
455
               foreach ($rejected as $id => $data) {
456
                  if ($action == 1) {
457
                     Session::addMessageAfterRedirect(sprintf(__('Email %s not found. Impossible import.'),
458
                                                              strtr($id, $clean)),
459
                                                      false, ERROR);
460
                  } else { // Delete data in notimportedemail table
461
                     $rejectedmail = new NotImportedEmail();
462
                     $rejectedmail->delete(array('id' => $data['id']));
458
            if(!in_array(1, $error)){// Entity UPGRADE
459
               // Email not present in mailbox
460
               if (count($rejected)) {
461
                  $clean = array('<' => '',
462
                                 '>' => '');
463
                  foreach ($rejected as $id => $data) {
464
                     if ($action == 1) {
465
                        Session::addMessageAfterRedirect(sprintf(__('Email %s not found. Impossible import.'),
466
                                                                 strtr($id, $clean)),
467
                                                         false, ERROR);
468
                     } else { // Delete data in notimportedemail table
469
                        $rejectedmail = new NotImportedEmail();
470
                        $rejectedmail->delete(array('id' => $data['id']));
471
                     }
463 472
                  }
464 473
               }
465 474
            }
inc/rule.class.php (working copy)
2409 2409
    * @param $sub_type
2410 2410
   **/
2411 2411
   static function getActionsByType($sub_type) {
2412

  
2413 2412
      if ($rule = getItemForItemtype($sub_type)) {
2414 2413
         return $rule->getAllActions();
2415 2414
      }
inc/ruleaction.class.php (working copy)
453 453
               switch($actions[$options["field"]]['type']) {
454 454
                  case "dropdown" :
455 455
                     $table   = $actions[$options["field"]]['table'];
456
                     $param['name'] = "value";
456
                     $param = array('name' => "value", 'check_ticket_edition_on_parent' => true);// Entity UPGRADE
457 457
                     if (isset($actions[$options["field"]]['condition'])) {
458 458
                        $param['condition'] = $actions[$options["field"]]['condition'];
459 459
                     }
460
                     // Entity UPGRADE
461
                     if (isset($actions[$options["field"]]['used'])) {
462
                        $param['used'] = $actions[$options["field"]]['used'];
463
                     }
464
                     // Entity UPGRADE
460 465
                     Dropdown::show(getItemTypeForTable($table), $param);
461 466
                     $display = true;
462 467
                     break;
inc/rulemailcollector.class.php (working copy)
185 185
      $actions['entities_id']['name']                       = __('Entity');
186 186
      $actions['entities_id']['type']                       = 'dropdown';
187 187
      $actions['entities_id']['table']                      = 'glpi_entities';
188
      // Entity UPGRADE
189
      // We get parent entities not allowed to create tickets
190
      $parent_entities_id = array();
191
      $data_entities = getAllDatasFromTable('glpi_entities');
192
      foreach($data_entities as $data){
193
         if((count(getSonsOf('glpi_entities', $data['id'])) > 1 || $data['id'] == 0) 
194
                 && !$data['ticket_edition_on_parent']){
195
            $parent_entities_id[] = $data['id'];
196
         }
197
      }
198
      $actions['entities_id']['used'] = $parent_entities_id;
199
      // Entity UPGRADE
188 200

  
189 201
      $actions['_affect_entity_by_domain']['name']          = __('Entity from domain');
190 202
      $actions['_affect_entity_by_domain']['type']          = 'text';
inc/ticket.class.php (working copy)
1107 1107

  
1108 1108
   function prepareInputForAdd($input) {
1109 1109
      global $CFG_GLPI;
1110
      
1111
      // Entity UPGRADE
1112
      //check if ticket is editable on parent entities
1113
      if(!self::checkTicketEditionOnParentEntity($input['entities_id'], true)){
1114
         $_SESSION["helpdeskSaved"] = $input;
1115
         return false;
1116
      }
1117
      // Entity UPGRADE
1118
       
1110 1119
      // save value before clean;
1111 1120
      $title = ltrim($input['name']);
1112 1121
      // Standard clean datas
......
3752 3761
      if ($ID > 0) {
3753 3762
         $this->check($ID, READ);
3754 3763
      } else {
3764
         // Entity UPGRADE
3765
         //check if ticket is editable on parent entities
3766
         if(!self::checkTicketEditionOnParentEntity()){
3767
            return false;
3768
         }
3769
         // Entity UPGRADE
3770
         
3755 3771
         // Create item
3756 3772
         $this->check(-1, CREATE, $values);
3757 3773
      }
......
6077 6093
      }
6078 6094
      return $values;
6079 6095
   }
6096
   
6097
   /**
6098
    * Check if ticket is editable on parent entities
6099
    *
6100
    * @param $entity : entity to check
6101
    * @param $messageAfterRedirect : true : add message after page reload, false : simple echo
6102
    * 
6103
    * @return bool
6104
   **/
6105
   static function checkTicketEditionOnParentEntity($entity=-1, $messageAfterRedirect=0) {   
6106
      // Entity UPGRADE
6107
      if($entity == -1) $entity = $_SESSION["glpiactive_entity"];
6108
      
6109
      // Check edition right on parent entity
6110
      if (!Entity::getUsedConfig('ticket_edition_on_parent', $entity)) {
6111
         $message =  __('Ticket edition on parent entity is not allowed');
6112
         if($messageAfterRedirect){
6113
            Session::addMessageAfterRedirect($message, true, ERROR);
6114
         } else {
6115
            echo "<h4><span class='red'>".$message."</span></h4>";
6116
         }
6117
         
6118
         return false;
6119
      }
6120
      
6121
      return true;
6122
      // Entity UPGRADE
6123
   }
6080 6124
}
6081
?>
6125
?>
install/mysql/glpi-0.85-empty.sql (working copy)
1871 1871
  `default_cartridges_alarm_threshold` int(11) NOT NULL DEFAULT '-2',
1872 1872
  `default_consumables_alarm_threshold` int(11) NOT NULL DEFAULT '-2',
1873 1873
  `delay_send_emails` int(11) NOT NULL DEFAULT '-2',
1874
  `ticket_edition_on_parent` int(11) NOT NULL DEFAULT '-2',
1874 1875
  PRIMARY KEY (`id`),
1875 1876
  UNIQUE KEY `unicity` (`entities_id`,`name`),
1876 1877
  KEY `entities_id` (`entities_id`)
1877 1878
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1878 1879

  
1879
INSERT INTO `glpi_entities` VALUES ('0','Entité racine','-1','Entité racine',NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'0',NULL,NULL,NULL,'0','0','0','0','0','0','0','0','0','-1','0','0','-10','1',NULL,'1','0','0',NULL,'0','0','0','0','0','1','-10','0','0','10','10','0');
1880
INSERT INTO `glpi_entities` VALUES ('0','Entité racine','-1','Entité racine',NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'0',NULL,NULL,NULL,'0','0','0','0','0','0','0','0','0','-1','0','0','-10','1',NULL,'1','0','0',NULL,'0','0','0','0','0','1','-10','0','0','10','10','0','1');
1880 1881

  
1881 1882
### Dump table glpi_entities_knowbaseitems
1882 1883

  
install/update_084_085.php (working copy)
1033 1033
      $DB->queryOrDie($query, "0.85 populate glpi_crontasks for queuemail");
1034 1034
   }
1035 1035

  
1036
   // Entity UPGRADE
1037
   $migration->addField('glpi_entities', 'ticket_edition_on_parent', 'integer',   array('value' => 1));
1038
   // Entity UPGRADE
1039
   
1040
   if ($migration->addField("glpi_entities", "delay_send_emails", "integer", array('value' => -2))) {
1036 1041
   if ($migration->addField("glpi_entities", "delay_send_emails", "integer",
1037 1042
                            array('value' => -2))) {
1038 1043
      $migration->migrationOneTable('glpi_entities');