示例#1
0
 public static function uploadAttributeImage($details, $customSetParam, $db, $table, $name, $attributeID, $uploader_username)
 {
     $imageKeys = array();
     foreach ($details['name'] as $k => $v) {
         $imageKeys[] = $k;
     }
     Zend_Debug::dump($imageKeys);
     foreach ($imageKeys as $k => $v) {
         $hasImageError = false;
         $price_offset = $customSetParam[$name]['price'][$v];
         $detail_name = $customSetParam[$name]['name'][$v];
         $file['name'] = $details['name'][$v];
         $file['type'] = $details['type'][$v];
         $file['tmp_name'] = $details['tmp_name'][$v];
         $file['error'] = $details['error'][$v];
         $file['size'] = $details['size'][$v];
         //$file = $image;
         switch ($file['error']) {
             case UPLOAD_ERR_OK:
                 //echo "upload okay";
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 //$this->messenger->addMessage('The uploaded file is too large');
                 break;
             case UPLOAD_ERR_PARTIAL:
                 //$this->messenger->addMessage('The uploaded file was too large');
                 break;
             case UPLOAD_ERR_NO_FILE:
                 //$this->messenger->addMessage('No file was uploaded');
                 $hasImageError = true;
                 break;
             case UPLOAD_ERR_NO_TMP_DIR:
                 //$this->messenger->addMessage('Temporary folder not found');
                 $hasImageError = true;
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 //$this->messenger->addMessage('Unable to write file');
                 $hasImageError = true;
                 break;
             case UPLOAD_ERR_EXTENSION:
                 //$this->messenger->addMessage('Invalid file extension');
                 $hasImageError = true;
                 break;
             default:
                 $hasImageError = true;
                 //$this->messenger->addMessage('Unkonw error code');
         }
         if (!$hasImageError) {
             //start the process of imaging.
             $hasImageInfoError = false;
             $info = getImageSize($file['tmp_name']);
             if (!$info) {
                 $this->messenger->addMessage('Uploaded file was not an image');
             }
             //echo $info[2];
             switch ($info[2]) {
                 case IMAGETYPE_PNG:
                 case IMAGETYPE_GIF:
                 case IMAGETYPE_JPEG:
                 case IMAGETYPE_JPG:
                     break;
                 default:
                     $hasImageInfoError = true;
                     $this->messenger->addMessage('type', 'Invalid image type uploaded');
             }
             if (!$hasImageInfoError) {
                 $newImage = new DatabaseObject_Attribute_CustomAttributeDetails($db, $table);
                 echo 'table is: ' . $table . '<br/>';
                 echo 'name is: ' . $name . '<br/>';
                 $newImage->setSaveFilePath($uploader_username, $table, $name);
                 $newImage->details_name = $detail_name;
                 $newImage->price_offset = $price_offset;
                 $newImage->image_name = $file['name'];
                 //$newImage->setUsername(Zend_Auth::getInstance()->getIdentity()->username);
                 $newImage->set_id = $attributeID;
                 $newImage->uploadFile($file['tmp_name']);
                 $newImage->filename = basename($file['name']);
                 $newImage->save();
                 //this is the place to create all the neccessary thumbnails for the website.
                 echo 'here at creating the thumbnails -0<br />';
                 /*$newImage->createThumbnail(150, 200, 'homeFrontFour');
                 		echo 'here at creating the thumbnails -1<br />';*/
                 //$newImage->createThumbnail(300, 350, 'productDetailImage');
                 $newImage->createThumbnail(30, 30, 'miniDetailImage');
                 $newImage->createThumbnail(50, 70, 'smallDetailImage');
                 echo 'here at creating the thumbnails -3<br />';
                 /*$newImage->createThumbnail(200, 200, 'productFirstImage');
                 			echo 'here at creating the thumbnails -2<br />';
                 		
                 		$newImage->createThumbnail(30, 200, 'productSmallPreview');
                 			echo 'here at creating the thumbnails -4<br />';*/
             } else {
                 $newImage = new DatabaseObject_Attribute_CustomAttributeDetails($db, $table);
                 echo 'table is: ' . $table . '<br/>';
                 echo 'name is: ' . $name . '<br/>';
                 $newImage->setSaveFilePath($uploader_username, $table, $name);
                 $newImage->details_name = $detail_name;
                 $newImage->price_offset = $price_offset;
                 $newImage->image_name = $file['name'];
                 //$newImage->setUsername(Zend_Auth::getInstance()->getIdentity()->username);
                 $newImage->set_id = $attributeID;
                 $newImage->save();
             }
         } else {
             $newImage = new DatabaseObject_Attribute_CustomAttributeDetails($db, $table);
             echo 'table is: ' . $table . '<br/>';
             echo 'name is: ' . $name . '<br/>';
             $newImage->setSaveFilePath($uploader_username, $table, $name);
             $newImage->details_name = $detail_name;
             $newImage->price_offset = $price_offset;
             $newImage->image_name = $file['name'];
             //$newImage->setUsername(Zend_Auth::getInstance()->getIdentity()->username);
             $newImage->set_id = $attributeID;
             $newImage->save();
         }
     }
 }
 public function uploadattributeAction()
 {
     //action= 1 = new //action= 2 = add //action= 3 = delete //action= 0 =view
     $action = $this->request->getParam('actioncall');
     //echo 'action is '.$action;
     if (!isset($action) || $action < 0 && $action > 3 || !is_numeric($action)) {
         echo 'invalid action';
         //invalid action.
     } elseif ($action == 1) {
         //1 new.
         //need the action, paramSet
         echo 'action 1';
         $table = $this->request->getParam('paramSet');
         $table_details = $table . '_details';
         //$paramSet = 'fabricSet';
         Zend_Debug::dump($_FILES);
         //addition of new attributes.
         $fp = new FormProcessor_Attribute_CustomAttribute($this->db, $table, $this->signedInUserSessionInfoHolder->generalInfo->userID);
         if ($this->request->isPost()) {
             echo 'here at post<br />';
             if ($fp->process($this->request)) {
                 echo 'it is processed';
                 Zend_Debug::dump($_FILES);
                 //Zend_Debug::dump($v);
                 //echo 'product name is: '.$fp->product->name;
                 echo 'the name of customeSetName is: ' . $fp->customSetName[0];
                 DatabaseObject_Helper_ImageUpload::uploadAttributeImage($_FILES['customAttributeDetailImage'], $fp->customSetParam, $this->db, $table_details, $fp->customSetName[0], $fp->attributeID, $this->signedInUserSessionInfoHolder->generalInfo->username);
                 //redirect back to product listing/where they came from.
                 //$this->_redirect("/manageattribute/uploadattribute?actioncall=0&paramSet=$table&id=$fp->attributeID");
                 $this->messenger->addMessage('Attribute set has been added');
                 $this->_redirect($_SERVER['HTTP_REFERER']);
             } else {
                 echo "it is not processed.";
                 $this->messenger->addMessage('it is not processed, there is a duplicate');
                 $this->_redirect($_SERVER['HTTP_REFERER']);
                 //add message and redirect back to product listing where they came from.
             }
         }
     } elseif ($action == 2) {
         //add
         //need id of attribute_table
         //need the paramSet
         $id = $this->request->getParam('id');
         if (isset($id) || $id > 0 && is_numeric($id)) {
             //load attribute
             $table = $this->request->getParam('paramSet');
             $table_details = $table . '_details';
             //check fabric id is valid
             $fabricSet = DatabaseObject_Helper_ManageAttribute::confirmattributeidwithuploader($this->db, $table, $this->signedInUserSessionInfoHolder->generalInfo->userID, $id);
             if (count($fabricSet) == 1) {
                 $fp = new FormProcessor_Attribute_CustomAttribute($this->db, $table, $this->signedInUserSessionInfoHolder->generalInfo->userID);
                 //load load id for attributeSet
                 if ($fp->load($id)) {
                     //if uploaded
                     if ($this->request->isPost()) {
                         //process image upload
                         $customSetParam = $this->request->getParam('attributeSet');
                         //upload attribute details for image upload;
                         DatabaseObject_Helper_ImageUpload::uploadAttributeImage($_FILES['customAttributeDetailImage'], $customSetParam, $this->db, $table_details, $fp->customSet->name_of_set, $fp->customSet->getId(), $this->signedInUserSessionInfoHolder->generalInfo->username);
                         echo 'finished upload';
                         $this->_redirect("/manageattribute/uploadattribute?actioncall=0&paramSet={$table}&id={$id}");
                         $this->_redirect($_SERVER['HTTP_REFERER']);
                     }
                 }
                 //$this->view->attribute = $attribute;
             } else {
                 $this->messenger->addMessage('sorry you do not have permission to edit this attribute');
                 $this->_redirect($_SERVER['HTTP_REFERER']);
             }
             //edit existing attribute status
         }
     } elseif ($action == 3) {
         //3 delete
         //need id of attribute_detail id
         //need paramSet_detail list
         echo 'action is 3';
         if ($this->request->isPost()) {
             $ids = $this->request->getParam('image_id');
             //$attribute_name = $this->request->getParam('attribute_name');
             $table = $this->request->getParam('paramSet');
             $table_details = $table . '_details';
             Zend_Debug::dump($ids);
             if (isset($ids) || count($ids) > 0) {
                 foreach ($ids as $k => $v) {
                     $image = new DatabaseObject_Attribute_CustomAttributeDetails($this->db, $table_details);
                     if ($image->loadForPost($this->signedInUserSessionInfoHolder->generalInfo->username, $v)) {
                         $attributeSetTmp = DatabaseObject_Helper_ManageAttribute::receiveAttributeSetFromId($this->db, $table, $image->set_id);
                         Zend_Debug::dump($attributeSetTmp);
                         $image->setSaveFilePath($this->signedInUserSessionInfoHolder->generalInfo->username, $table_details, $attributeSetTmp[0]['name_of_set']);
                         //this has to be set for every operation that usesthe get thumbnail path.
                         $image->delete();
                     }
                 }
                 $this->_redirect($_SERVER['HTTP_REFERER']);
             } else {
                 $this->messenger->addMessage('You must select an attribute to delete');
                 $this->_redirect($_SERVER['HTTP_REFERER']);
             }
         }
     } elseif ($action == 0) {
         //view details
         echo 'action is 0';
         $id = $this->request->getParam('id');
         if (isset($id) || $id > 0 && is_numeric($id)) {
             $table = $this->request->getParam('paramSet');
             $attributeSet = DatabaseObject_Helper_ManageAttribute::confirmattributeidwithuploader($this->db, $table, $this->signedInUserSessionInfoHolder->generalInfo->userID, $id);
             if (count($attributeSet) == 1) {
                 Zend_Debug::dump($attributeSet);
                 echo 'here at exisitng attribute';
                 $attribute = DatabaseObject_Helper_ManageAttribute::loadAttributeIdDetail($this->db, $table, $id);
                 Zend_Debug::dump($attribute);
                 $this->view->attribute = $attribute;
             } else {
                 //$this->messenger->addMessage('sorry you do not have permission to edit this attribute');
                 echo 'can not load this attribute';
             }
         } else {
             echo 'you must provide an specific id';
         }
     }
     //only new fabric sets will be generated
 }
 public static function removeAttributeForUser($db, $attributeType, $attributeID, $username)
 {
     $select = $db->select();
     $select->from($attributeType, '*')->where('id=?', $attributeID);
     $attributeSet = $db->fetchAll($select);
     Zend_Debug::dump($attributeSet);
     $select = $db->select();
     $select->from($attributeType . '_details', '*')->where('set_id = ?', $attributeID);
     //echo $select;
     $attributeDetails = $db->fetchAll($select);
     //$attributeEverything = $db->fetchAll('$select');
     //Zend_Debug::dump($attributeEverything);
     //Zend_Debug::dump($attributeDetails);
     foreach ($attributeDetails as $k => $v) {
         echo 'here at delete details';
         $detailsImage = new DatabaseObject_Attribute_CustomAttributeDetails($db, $attributeType . '_details');
         echo 'id is: ' . $v['id'];
         //$detailsImage->load($v['id']);
         if ($detailsImage->load($v['id'])) {
             echo 'here at image delete';
             $detailsImage->setSaveFilePath($username, $attributeType . '_details', $attributeSet[0]['name_of_set']);
             $detailsImage->delete();
         }
     }
     $where = array($attributeType . '_id = ' . $attributeID);
     //echo 'product_'.$table.'_id: '.$product_attribute_set_id;
     $db->delete('product_' . $attributeType, $where);
     $where2 = array('id = ' . $attributeID);
     $db->delete($attributeType, $where2);
 }