Example #1
0
 public function update()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', $this->get_class(), $this->promo->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     $cover = OAInput::file('cover');
     if (!((string) $this->promo->cover || $cover)) {
         return redirect_message(array('admin', $this->get_class(), $this->promo->id, 'edit'), array('_flash_message' => '請選擇圖片(gif、jpg、png)檔案!', 'posts' => $posts));
     }
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', $this->get_class(), $this->promo->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     if ($columns = array_intersect_key($posts, $this->promo->table()->columns)) {
         foreach ($columns as $column => $value) {
             $this->promo->{$column} = $value;
         }
     }
     $promo = $this->promo;
     $update = Promo::transaction(function () use($promo, $cover) {
         if (!$promo->save()) {
             return false;
         }
         if ($cover && !$promo->cover->put($cover)) {
             return false;
         }
         return true;
     });
     if (!$update) {
         return redirect_message(array('admin', $this->get_class(), $this->promo->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
     }
     return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '更新成功!'));
 }
Example #2
0
 public function ckeditors_upload_image()
 {
     $funcNum = $_GET['CKEditorFuncNum'];
     $upload = OAInput::file('upload');
     if (!($upload && verifyCreateOrm($img = CkeditorPicture::create(array('name' => ''))) && $img->name->put($upload, true))) {
         echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction ({$funcNum}, '', '上傳失敗!');</script>";
     } else {
         echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction ({$funcNum}, '" . $img->name->url('400h') . "', '上傳成功!');</script>";
     }
 }
Example #3
0
 public function update()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     $posts['content'] = OAInput::post('content', false);
     $cover = OAInput::file('cover');
     if (!((string) $this->article->cover || $cover)) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '請選擇圖片(gif、jpg、png)檔案!', 'posts' => $posts));
     }
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     if ($columns = array_intersect_key($posts, $this->article->table()->columns)) {
         foreach ($columns as $column => $value) {
             $this->article->{$column} = $value;
         }
     }
     $article = $this->article;
     $update = ArticleTag::transaction(function () use($article, $cover) {
         if (!$article->save()) {
             return false;
         }
         if ($cover && !$article->cover->put($cover)) {
             return false;
         }
         return true;
     });
     if (!$update) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
     }
     $ori_ids = column_array($article->mappings, 'article_tag_id');
     if (($del_ids = array_diff($ori_ids, $posts['tag_ids'])) && ($mappings = ArticleTagMapping::find('all', array('select' => 'id, article_tag_id', 'conditions' => array('article_id = ? AND article_tag_id IN (?)', $article->id, $del_ids))))) {
         foreach ($mappings as $mapping) {
             ArticleTagMapping::transaction(function () use($mapping) {
                 return $mapping->destroy();
             });
         }
     }
     if (($add_ids = array_diff($posts['tag_ids'], $ori_ids)) && ($tags = ArticleTag::find('all', array('select' => 'id', 'conditions' => array('id IN (?)', $add_ids))))) {
         foreach ($tags as $tag) {
             ArticleTagMapping::transaction(function () use($tag, $article) {
                 return verifyCreateOrm(ArticleTagMapping::create(Array_intersect_key(array('article_tag_id' => $tag->id, 'article_id' => $article->id), ArticleTagMapping::table()->columns)));
             });
         }
     }
     if ($article->sources) {
         foreach ($article->sources as $source) {
             ArticleSource::transaction(function () use($source) {
                 return $source->destroy();
             });
         }
     }
     if ($posts['sources']) {
         foreach ($posts['sources'] as $i => $source) {
             ArticleSource::transaction(function () use($i, $source, $article) {
                 return verifyCreateOrm(ArticleSource::create(array_intersect_key(array_merge($source, array('article_id' => $article->id, 'sort' => $i)), ArticleSource::table()->columns)));
             });
         }
     }
     $this->_clean_cell($article);
     return redirect_message(($url = Session::getData('admin_articles_index_url')) ? $url : array('admin', $this->get_class()), array('_flash_message' => '更新成功!'));
 }
Example #4
0
 public function update()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', $this->get_class(), $this->invoice->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     $cover = OAInput::file('cover');
     // if (!((string)$this->invoice->cover || $cover))
     //   return redirect_message (array ('admin', $this->get_class (), $this->invoice->id, 'edit'), array (
     //       '_flash_message' => '請選擇圖片(gif、jpg、png)檔案!',
     //       'posts' => $posts
     //     ));
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', $this->get_class(), $this->invoice->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     if ($columns = array_intersect_key($posts, $this->invoice->table()->columns)) {
         foreach ($columns as $column => $value) {
             $this->invoice->{$column} = $value;
         }
     }
     $invoice = $this->invoice;
     $update = InvoiceTag::transaction(function () use($invoice, $cover) {
         if (!$invoice->save()) {
             return false;
         }
         if ($cover && !$invoice->cover->put($cover)) {
             return false;
         }
         return true;
     });
     if (!$update) {
         return redirect_message(array('admin', $this->get_class(), $this->invoice->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
     }
     if (($del_ids = array_diff(column_array($invoice->pictures, 'id'), $posts['pic_ids'])) && ($pictures = InvoicePicture::find('all', array('select' => 'id, name', 'conditions' => array('id IN (?)', $del_ids))))) {
         foreach ($pictures as $picture) {
             InvoicePicture::transaction(function () use($picture) {
                 return $picture->destroy();
             });
         }
     }
     if ($pictures = OAInput::file('pictures[]')) {
         foreach ($pictures as $picture) {
             InvoicePicture::transaction(function () use($picture, $invoice) {
                 return verifyCreateOrm($pic = InvoicePicture::create(array_intersect_key(array_merge($picture, array('invoice_id' => $invoice->id)), InvoicePicture::table()->columns))) && $pic->name->put($picture);
             });
         }
     }
     return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '更新成功!'));
 }
Example #5
0
 public function update()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works', $this->work->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     $cover = OAInput::file('cover');
     if (!((string) $this->work->cover || $cover)) {
         return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works', $this->work->id, 'edit'), array('_flash_message' => '請選擇圖片(gif、jpg、png)檔案!', 'posts' => $posts));
     }
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works', $this->work->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     if ($columns = array_intersect_key($posts, $this->work->table()->columns)) {
         foreach ($columns as $column => $value) {
             $this->work->{$column} = $value;
         }
     }
     $work = $this->work;
     $update = WorkTag::transaction(function () use($work, $cover) {
         if (!$work->save()) {
             return false;
         }
         if ($cover && !$work->cover->put($cover)) {
             return false;
         }
         return true;
     });
     if (!$update) {
         return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works', $this->work->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
     }
     if (($del_ids = array_diff(column_array($work->pictures, 'id'), $posts['pic_ids'])) && ($pictures = WorkPicture::find('all', array('select' => 'id, name', 'conditions' => array('id IN (?)', $del_ids))))) {
         foreach ($pictures as $picture) {
             WorkPicture::transaction(function () use($picture) {
                 return $picture->destroy();
             });
         }
     }
     if ($pictures = OAInput::file('pictures[]')) {
         foreach ($pictures as $picture) {
             WorkPicture::transaction(function () use($picture, $work) {
                 return verifyCreateOrm($pic = WorkPicture::create(array_intersect_key(array_merge($picture, array('work_id' => $work->id)), WorkPicture::table()->columns))) && $pic->name->put($picture);
             });
         }
     }
     $clean_blocks = WorkBlock::transaction(function () use($work) {
         foreach ($work->blocks as $block) {
             if (!$block->destroy()) {
                 return false;
             }
         }
         return true;
     });
     if ($blocks = $posts['blocks']) {
         foreach ($blocks as $block) {
             if (!($b = null) && WorkBlock::transaction(function () use($block, $work, &$b) {
                 return verifyCreateOrm($b = WorkBlock::create(array_intersect_key(array_merge($block, array('work_id' => $work->id)), WorkBlock::table()->columns)));
             })) {
                 if (($items = $block['items']) && $b) {
                     foreach ($items as $item) {
                         WorkBlockItem::transaction(function () use($item, $b) {
                             return verifyCreateOrm(WorkBlockItem::create(array_intersect_key(array_merge($item, array('work_block_id' => $b->id)), WorkBlockItem::table()->columns)));
                         });
                     }
                 }
             }
         }
     }
     return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works', $this->work->id, 'edit'), array('_flash_message' => '更新成功!'));
 }