Ejemplo n.º 1
0
 function adminaddAction()
 {
     $this->_helper->layout->setLayout("layout_admin");
     $brandTable = new Brands();
     $order = "create_date desc";
     $this->view->brands = $brandTable->fetchAll(null, $order, null, null);
     if ($this->_request->isPost()) {
         //post method
         $formData = $this->_request->getPost();
         //get background image
         $imgfile = $_FILES['background'];
         $imgdata = null;
         if (is_array($imgfile)) {
             $name = $imgfile['name'];
             $type = $imgfile['type'];
             $size = $imgfile['size'];
             if (!preg_match('/^image\\//i', $type) ? true : false) {
                 $this->view->error = "请上传正确的图片";
             } else {
                 if ($size > 2000000) {
                     $this->view->error = "图片不得超过2M";
                 } else {
                     $tmpfile = $imgfile['tmp_name'];
                     $file = fopen($tmpfile, "rb");
                     $imgdata = base64_encode(fread($file, $size));
                     fclose($file);
                     $this->view->error = "上传成功";
                 }
             }
         }
         //save mission
         $missionTable = new Missions();
         $newMission = $missionTable->createRecord($formData['title'], $formData['intro'], $formData['type'], $formData['startdate'], $formData['enddate'], $imgdata, $type, $formData['brand']);
         if ($newMission > 0) {
             $result = "Success";
             $this->_helper->redirector('adminlist', 'mission', null, array('id' => $formData['brand']));
         }
     } else {
         //get method
         $fc = Zend_Controller_Front::getInstance();
         $this->view->oFCKeditor = new FCKeditor("long_desc");
         $this->view->oFCKeditor->BasePath = $fc->getBaseUrl() . "/js/fckeditor/";
         $this->view->oFCKeditor->Height = "500px";
         $this->view->oFCKeditor->Width = "700px";
         if ($this->view->product['long_desc'] != null && $this->view->product['long_desc'] != '') {
             $this->view->oFCKeditor->Value = $this->view->product['long_desc'];
         }
     }
 }