Example #1
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return     string
  */
 public function ajaxRemoveTask()
 {
     // Check for request forgeries
     Request::checkToken(array('get', 'post')) or jexit('Invalid Token');
     // Ensure we have an ID to work with
     $id = Request::getInt('id', 0);
     if (!$id) {
         echo json_encode(array('error' => Lang::txt('COM_STOREFRONT_ERROR_NO_ID')));
         return;
     }
     $type = strtolower(Request::getWord('type', ''));
     $imgId = Request::getVar('currentfile', '');
     // Instantiate a model, change some info and save
     switch ($type) {
         case 'product':
             $object = new Product($id);
             $object->removeImage($imgId);
             break;
         case 'collection':
             $object = new Collection($id);
             $object->removeImage($imgId);
             break;
         default:
             echo json_encode(array('error' => Lang::txt('COM_STOREFRONT_ERROR_INVALID_TYPE')));
             return;
             break;
     }
     if (!$object->save()) {
         echo json_encode(array('error' => 'Error saving object'));
         return;
     }
     //echo result
     echo json_encode(array('success' => true, 'file' => '', 'id' => $id, 'size' => 0, 'width' => 0, 'height' => 0));
 }