示例#1
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $knowledge = new Knowledge($id);
         $_POST['title'] = lang_encode($_POST['title']);
         $_POST['intro'] = lang_encode($_POST['intro']);
         $_POST['detail'] = lang_encode($_POST['detail']);
         $_POST['start_date'] = Date2DB($_POST['start_date']);
         $_POST['end_date'] = Date2DB($_POST['end_date']);
         if (!$id) {
             $_POST['user_id'] = $this->session->userdata('id');
         }
         if ($_FILES['image']['name']) {
             if ($id) {
                 $knowledge->delete_file('uploads/knowledge/thumbnail', 'image');
             }
             $knowledge->image = $knowledge->upload($_FILES['image'], 'uploads/knowledge/thumbnail', 77, 64);
         }
         $knowledge->from_array($_POST);
         $knowledge->save();
         fix_file($_FILES['file']);
         foreach ($_POST['doc'] as $key => $doc) {
             if (@$_FILES['file'][$key]['name'] || @$_POST['doc_id'][$key]) {
                 $knowledge_file = new Knowledge_file(@$_POST['doc_id'][$key]);
                 if ($_FILES['file'][$key]['name']) {
                     if (@$_POST['doc_id'][$key]) {
                         $knowledge_file->delete_file('uploads/knowledge', 'file');
                     }
                     $knowledge_file->file = $knowledge_file->upload($_FILES['file'][$key], 'uploads/knowledge');
                 }
                 $knowledge_file->name = $doc;
                 $knowledge_file->knowledge_id = $knowledge->id;
                 $knowledge_file->save();
             }
         }
         set_notify('success', lang('save_data_complete'));
         redirect($_POST['referer']);
     }
 }