Esempio n. 1
0
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 Webapplications. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$web = new PluginWebapplicationsWebapplication();
$web_item = new PluginWebapplicationsWebapplication_Item();
if (isset($_POST["add"])) {
    $web->check(-1, 'w', $_POST);
    $newID = $web->add($_POST);
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $web->check($_POST['id'], 'w');
        $web->delete($_POST);
        $web->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $web->check($_POST['id'], 'w');
            $web->restore($_POST);
            $web->redirectToList();
        } else {
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 Webapplications. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$web = new PluginWebapplicationsWebapplication();
$web_item = new PluginWebapplicationsWebapplication_Item();
if (isset($_POST["add"])) {
    $web->check(-1, CREATE, $_POST);
    $newID = $web->add($_POST);
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $web->check($_POST['id'], DELETE);
        $web->delete($_POST);
        $web->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $web->check($_POST['id'], PURGE);
            $web->restore($_POST);
            $web->redirectToList();
        } else {
Esempio n. 3
0
function plugin_webapplications_MassiveActionsProcess($data)
{
    $web_item = new PluginWebapplicationsWebapplication_Item();
    $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
    switch ($data['action']) {
        case "plugin_webapplications_add_item":
            foreach ($data["item"] as $key => $val) {
                if ($val == 1) {
                    $input = array('plugin_webapplications_webapplications_id' => $data['plugin_webapplications_webapplications_id'], 'items_id' => $key, 'itemtype' => $data['itemtype']);
                    if ($web_item->can(-1, 'w', $input)) {
                        if ($web_item->add($input)) {
                            $res['ok']++;
                        } else {
                            $res['ko']++;
                        }
                    } else {
                        $res['noright']++;
                    }
                }
            }
            break;
    }
    return $res;
}
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     $web_item = new PluginWebapplicationsWebapplication_Item();
     switch ($ma->getAction()) {
         case "plugin_webapplications_add_item":
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 $input = array('plugin_webapplications_webapplications_id' => $input['plugin_webapplications_webapplications_id'], 'items_id' => $id, 'itemtype' => $item->getType());
                 if ($web_item->can(-1, UPDATE, $input)) {
                     if ($web_item->add($input)) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             }
             return;
         case "transfer":
             $input = $ma->getInput();
             if ($item->getType() == 'PluginWebapplicationsWebapplication') {
                 foreach ($ids as $key) {
                     $item->getFromDB($key);
                     $type = PluginWebapplicationsWebapplicationType::transfer($item->fields["plugin_webapplications_webapplicationtypes_id"], $input['entities_id']);
                     if ($type > 0) {
                         $values["id"] = $key;
                         $values["plugin_webapplications_webapplicationtypes_id"] = $type;
                         $item->update($values);
                     }
                     unset($values);
                     $values["id"] = $key;
                     $values["entities_id"] = $input['entities_id'];
                     if ($item->update($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             return;
         case 'install':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($item->can($key, UPDATE)) {
                     $values = array('plugin_webapplications_webapplications_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($web_item->add($values)) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'uninstall':
             $input = $ma->getInput();
             foreach ($ids as $key) {
                 if ($val == 1) {
                     if ($web_item->deleteItemByWebApplicationsAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 /**
  * Do the specific massive actions
  *
  * @since version 0.84
  * 
  * @param $input array of input datas
  * 
  * @return an array of results (nbok, nbko, nbnoright counts)
  **/
 public function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $web_item = new PluginWebapplicationsWebapplication_Item();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginWebapplicationsWebapplication') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $type = PluginWebapplicationsWebapplicationType::transfer($this->fields["plugin_webapplications_webapplicationtypes_id"], $input['entities_id']);
                         if ($type > 0) {
                             $values["id"] = $key;
                             $values["plugin_webapplications_webapplicationtypes_id"] = $type;
                             if ($this->update($values)) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         }
                         unset($values);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Install":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     $values = array('plugin_webapplications_webapplicationtypes_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($web_item->add($values)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Desinstall":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($web_item->deleteItemByWebApplicationsAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
             break;
     }
     return $res;
 }