Exemplo n.º 1
0
 /**
  * Do the specific massive actions
  *
  * @since version 0.84
  *
  * @param $input array of input datas
  *
  * @return an array of results (nbok, nbko, nbnoright counts)
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $criteria = new PluginTypologyTypologyCriteria();
     switch ($input['action']) {
         case "deleteAll":
             if ($input['itemtype'] == 'PluginTypologyTypologyCriteria') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($criteria->can($key, 'w')) {
                             if ($criteria->delete(array('id' => $key))) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         }
                     }
                 }
             }
             break;
         case "updateAll":
             if ($input['itemtype'] == 'PluginTypologyTypologyCriteria') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $values = array('id' => $key, 'is_active' => $input['is_active']);
                         if ($criteria->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
Exemplo n.º 2
0
 Typology is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Typology. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
$typo = new PluginTypologyTypology();
$criteria = new PluginTypologyTypologyCriteria();
if (isset($_POST["update"])) {
    $criteria->check($_POST["id"], 'w');
    $criteria->update($_POST);
    Html::back();
} else {
    if (isset($_POST["add"])) {
        $criteria->check(-1, 'w', $_POST);
        $newID = $criteria->add($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . "/plugins/typology/front/typologycriteria.form.php?id={$newID}");
    } else {
        if (isset($_POST["delete"])) {
            /*if (isset($_POST["item"]) && count($_POST["item"])) {
                  foreach ($_POST["item"] as $key => $val) {
                     if ($val == 1) {
                        if ($criteria->can($key, 'w')) {
                           $criteria->delete(array('id' => $key));
                        }
                     }
Exemplo n.º 3
0
 /**
  * Do the specific massive actions
  *
  * @since version 0.84
  *
  * @param $input array of input datas
  *
  * @return an array of results (nbok, nbko, nbnoright counts)
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $criteria = new PluginTypologyTypologyCriteria();
     $definition = new PluginTypologyTypologyCriteriaDefinition();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginTypologyTypology') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $restrict = "`plugin_typology_typologies_id` = '" . $key . "'";
                         $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict);
                         if (!empty($crits)) {
                             foreach ($crits as $crit) {
                                 $criteria->getFromDB($crit["id"]);
                                 $condition = "`plugin_typology_typologycriterias_id` = '" . $crit["id"] . "'";
                                 $defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition);
                                 if (!empty($defs)) {
                                     foreach ($defs as $def) {
                                         $definition->getFromDB($def["id"]);
                                         unset($values);
                                         $values["id"] = $def["id"];
                                         $values["entities_id"] = $input['entities_id'];
                                         $definition->update($values);
                                     }
                                 }
                                 unset($values);
                                 $values["id"] = $crit["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $criteria->update($values);
                             }
                         }
                         unset($values);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Duplicate":
             if ($input['itemtype'] == 'PluginTypologyTypology') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $restrict = "`plugin_typology_typologies_id` = '" . $key . "'";
                         $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict);
                         unset($this->fields["id"]);
                         $this->fields["name"] = addslashes($this->fields["name"] . " Copy");
                         $this->fields["comment"] = addslashes($this->fields["comment"]);
                         $this->fields["notepad"] = addslashes($this->fields["notepad"]);
                         $newIDtypo = $this->add($this->fields);
                         if ($newIDtypo) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                         if (!empty($crits)) {
                             foreach ($crits as $crit) {
                                 $criteria->getFromDB($crit["id"]);
                                 $condition = "`plugin_typology_typologycriterias_id` = '" . $crit["id"] . "'";
                                 $defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition);
                                 unset($criteria->fields["id"]);
                                 $criteria->fields["name"] = addslashes($criteria->fields["name"]);
                                 $criteria->fields["plugin_typology_typologies_id"] = $newIDtypo;
                                 $criteria->fields["itemtype"] = addslashes($criteria->fields["itemtype"]);
                                 $newIDcrit = $criteria->add($criteria->fields);
                                 if (!empty($defs)) {
                                     foreach ($defs as $def) {
                                         $definition->getFromDB($def["id"]);
                                         unset($definition->fields["id"]);
                                         $definition->fields["plugin_typology_typologycriterias_id"] = $newIDcrit;
                                         $definition->fields["field"] = addslashes($definition->fields["field"]);
                                         $definition->fields["action_type"] = addslashes($definition->fields["action_type"]);
                                         $definition->fields["value"] = addslashes($definition->fields["value"]);
                                         $definition->add($definition->fields);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }