コード例 #1
0
 /**
  * The Edit action of the Admin module should be triggered through an HTTP POST request
  * in order to edit a widget that is already installed in the widget repository.
  *
  * @param integer $category The category's identifier in which the updated widget will be assigned.
  * @param string $widget The widget's identifier relevant to the widget to update.
  */
 public function edit($category, $widget)
 {
     // Security check.
     if (!Auth::isAuth() && (Auth::isAdmin() || Auth::isGod())) {
         DefaultFC::redirection('users/index?ref=admin');
     }
     try {
         // When editing, two cases may occur :
         // 1. Both widget file (xml manifest or zip archive) and category
         //    are provided.
         // 2. Only the category is provided. Dev note: the $_FILES global has
         //    a strange behaviour when something is not provided... for instance
         //    if a file named 'widgetFile' was not uploaded, the $_FILES['widgetFile']['name']
         //    value will not be empty, or null, but filled with an empty string oO !
         $widgetName = null;
         if ($_FILES['widgetFile']['name'] == '') {
             // Case 1.
             $widgetName = Widgets::edit($widget, $category);
         } else {
             // Case 2.
             $widgetName = Widgets::edit($widget, $category, $_FILES['widgetFile']['name'], $_FILES['widgetFile']['tmp_name']);
         }
         // If we are here, no exceptions was thrown by Widgets::edit so we assume
         // as successful widget edition.
         $_SESSION['isError'] = false;
         $_SESSION['message'] = sprintf(__("Widget '%s' has been successfully updated."), $widgetName);
     } catch (Exception $e) {
         $_SESSION['isError'] = true;
         $_SESSION['message'] = __("The widget could not be updated.");
     }
     DefaultFC::redirection('admin/index');
 }