} } break; default: $errors['err']='Unknown action'; //print_r($_POST); } break; case 'topics': require_once(INCLUDE_DIR.'class.topic.php'); $do=strtolower($_POST['do']); switch($do){ case 'update': $topic = new Topic($_POST['topic_id']); if($topic && $topic->getId()) { if($topic->update($_POST,$errors)) $msg='Topic updated successfully'; elseif(!$errors['err']) $errors['err']='Error updating the topic'; }else{ $errors['err']='Internal error'; } break; case 'create': if(Topic::create($_POST,$errors)) $msg='Help topic created successfully'; elseif(!$errors['err']) $errors['err']='Unable to create the topic. Internal error'; break; case 'mass_process': if(!$_POST['tids'] || !is_array($_POST['tids'])) {
public function update_topic() { if (!isset($_POST['topic_id'])) { error(__("Error"), __("No topic ID specified.", "discuss")); } $topic = new Topic($_POST['topic_id']); if ($topic->no_results) { error(__("Error"), __("Invalid topic ID specified.", "discuss")); } if (!$topic->editable()) { show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this topic.", "discuss")); } $topic->update($_POST['title'], $_POST['description']); $files = array(); foreach ($_FILES['attachment'] as $key => $val) { foreach ($val as $file => $attr) { $files[$file][$key] = $attr; } } foreach ($files as $attachment) { if ($attachment['error'] != 4) { $path = upload($attachment, null, "attachments"); Attachment::add(basename($path), $path, "topic", $topic->id); } } Flash::notice(__("Topic updated.", "discuss"), $topic->url()); }
$manager = new CategorieManager($link); try { $manager->create($_POST['nom']); } catch (Exception $e) { $error = $e->getMessage(); } } elseif (isset($_POST['delete'], $_GET['id'])) { $manager = new CategorieManager($link); $manager->delete($_GET['id']); } elseif (isset($_POST['update'], $_POST['nom'], $_GET['id'])) { $manager = new CategorieManager($link); $category = $manager->select($_GET['id']); $category->setTitre($_POST['nom']); $manager->update($category); } elseif (isset($_POST['update'], $_POST['statut'], $_GET['id'])) { $manager = new UserManager($link); $user = $manager->selectById($_GET['id']); $user->setStatut($_POST['statut']); $manager->update($user); } elseif (isset($_POST['bannir'], $_GET['id'])) { $manager = new UserManager($link); $user = $manager->selectById($_GET['id']); $manager->ban($user); } elseif (isset($_POST['reset'], $_GET['id'])) { // /!\ $topic = new Topic($link); $message = $topic->selectById($_GET['id']); $message->resetSignalement(); $topic->update($message); } }
} // Process reply if (isset($_POST['edit_content'])) { // Create Data Array $data = array(); $data['topic_id'] = $_GET['topic']; $data['body'] = $_POST['body']; // Getiing values from the SESSION vars $data['user_id'] = getUser()['user_id']; // Create Validator Object $validate = new Validator(); // Required fields $field_array = array('body'); if ($validate->isRequired($field_array)) { // Save Reply if ($topic->update($data)) { redirect('topic.php?id=' . $topic_id, 'Your post has succesfully saved', 'success'); } else { redirect('topic.php?id=' . $topic_id, 'Something went wrong with your edit', 'error'); } } else { redirect('topic.php?id=' . $topic_id, 'Your edit form is blank', 'error'); } } // Get Template & Assign vars (Getting Template Obj) $template = new Template('templates/editp.php'); //print_r($topic->getTopic($topic_id)); // Assign vars $template->topicId = $topic_id; $template->MainTopic = $topic->getTopic($topic_id); $template->replies = $topic->getReplies($topic_id);
function test_update() { $name = "Writing"; $test_topic = new Topic($name); $test_topic->save(); $name2 = "Interview"; $test_topic->update($name2); $topics = Topic::getAll(); $result = $topics[0]->getName(); $this->assertEquals($name2, $result); }