/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $val = $this->contactRepository->getCreateForm();
     if (!$val->isValid()) {
         return Redirect::back()->with('errors', $val->getErrors())->withInput();
     }
     $contact = $this->contactRepository->getFirst();
     if ($contact) {
         if (!$this->contactRepository->update($contact->id, $val->getInputData())) {
             return Redirect::back()->with('errors', $this->contactRepository->errors())->withInput();
         }
     } else {
         if (!$this->contactRepository->create($val->getInputData())) {
             return Redirect::back()->with('errors', $this->contactRepository->errors())->withInput();
         }
     }
     return Redirect::action('AdminContactsController@index')->with('success', 'Saved');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $this->categoryRepository->findById($id);
     $val = $this->categoryRepository->getEditForm($id);
     if (!$val->isValid()) {
         return Redirect::back()->with('errors', $val->getErrors())->withInput();
     }
     if (!$this->categoryRepository->update($id, $val->getInputData())) {
         return Redirect::back()->with('errors', $this->categoryRepository->errors())->withInput();
     }
     return Redirect::action('AdminCategoriesController@index')->with('success', 'Updated');
 }
Example #3
0
 function testUpdate()
 {
     //Arrange
     $name = "Work stuff";
     $id = 1;
     $test_category = new Category($name, $id);
     $test_category->save();
     $new_name = "Home stuff";
     //Act
     $test_category->update($new_name);
     //Assert
     $this->assertEquals("Home stuff", $test_category->getName());
 }
 public static function update($categoryId)
 {
     $params = $_POST;
     $categoryAttributes = array('name' => $params['name'], 'id' => $categoryId);
     $category = new Category($categoryAttributes);
     $categoryErrors = $category->errors();
     if (count($categoryErrors) == 0) {
         $category->update();
         Redirect::to('/category', array('message' => 'Luokkaa muokattu onnistuneesti.'));
     } else {
         View::make('/reminders/edit_category.html', array('categoryErrors' => $categoryErrors, 'category' => $categoryAttributes));
     }
 }
 /**
  * 添加、修改分类结果
  */
 public function actionModified()
 {
     $Category = new Category();
     $data = WaveCommon::getFilter($_POST);
     $cid = (int) $data['cid'];
     unset($data['cid']);
     if ($cid == 0) {
         $Category->insert($data);
     } else {
         $Category->update($data, array('cid' => $cid));
     }
     $this->jumpBox('成功!', Wave::app()->homeUrl . 'categories', 1);
 }
Example #6
0
 function init()
 {
     $obj = new Category();
     $func = array_shift($this->param);
     $id = array_shift($this->param);
     if ($func != '') {
         $_SERVER['REQUEST_METHOD'] = 'POST';
         switch ($func) {
             case 'add':
                 $data['parent_id'] = $id;
                 $data['name'] = $_POST['name'];
                 $data['active'] = true;
                 try {
                     $obj->add($data);
                 } catch (Exception $e) {
                 }
                 header('Location: /admin_categories');
                 exit;
                 break;
             case 'save':
                 $data['name'] = $_POST['name'];
                 try {
                     $obj->update($id, $data);
                 } catch (Exception $e) {
                 }
                 header('Location: /admin_categories');
                 exit;
                 break;
             case 'delete':
                 try {
                     $obj->delete($id);
                 } catch (Exception $e) {
                 }
                 header('Location: /admin_categories');
                 exit;
                 break;
             case 'activate':
                 try {
                     $obj->invert($id);
                 } catch (Exception $e) {
                 }
                 header('Location: /admin_categories');
                 exit;
                 break;
         }
     }
 }
 public function update()
 {
     $Category = new Category($this->db, $this->plural_resorce);
     if ($_POST['edited_categoryname'] != '') {
         $Category = new Category($this->db, $this->plural_resorce);
         $sql = $Category->update();
         mysqli_query($this->db, $sql) or die(mysqli_error($this->db));
     }
     if (isset($_POST['category_id'])) {
         $param = $_POST['category_id'];
         header("Location: ../task/index?category_id={$param}");
         exit;
     } else {
         header('Location: ../task/index');
         exit;
     }
 }
 public function createOrUpdateAttribute($attrs)
 {
     return;
     $fromto = array('term_id' => 'term_id', 'name' => 'name', 'slug' => 'slug', 'term_group' => 'group_id', 'term_taxonomy_id' => 'taxonomy_id', 'description' => 'description', 'parent' => 'parent_id', 'count' => 'count');
     $new_attrs = array();
     foreach ($fromto as $key => $nkey) {
         if (isset($attrs[$key])) {
             $new_attrs[$nkey] = $attrs[$key];
         }
     }
     $cat = new Category();
     if (isset($new_attrs['id']) && !empty($new_attrs['id'])) {
         $cat->update($new_attrs);
     } else {
         $cat->create($new_attrs);
     }
 }
<?php

require_once '../model/paths.php';
$session = new Session();
if (!$session->isLogin) {
    redirect("../login.php");
}
$database = new Database();
$user = new User();
$category = new Category();
if ($_POST['category']) {
    $category->setCategoryId($database->escapeString($_POST['categoryId']));
    foreach ($_POST as $key => $value) {
        if ($key == "categoryId" || $key == "submit") {
            continue;
        }
        $category->update($database, $key, $value);
    }
    redirect("../posts.php?posts=4&category={$_POST['categoryId']}");
} else {
    echo "<h2>Problem in editing category. Try again later or contact your administrator.</h2>";
}
Example #10
0
function finish_installation($password)
{
    require_once LIB_PATH . 'osclass/model/Admin.php';
    require_once LIB_PATH . 'osclass/model/Category.php';
    require_once LIB_PATH . 'osclass/model/Item.php';
    require_once LIB_PATH . 'osclass/helpers/hPlugins.php';
    require_once LIB_PATH . 'osclass/compatibility.php';
    require_once LIB_PATH . 'osclass/plugins.php';
    $data = array();
    $mAdmin = new Admin();
    $mPreference = Preference::newInstance();
    $mPreference->insert(array('s_section' => 'osclass', 's_name' => 'osclass_installed', 's_value' => '1', 'e_type' => 'BOOLEAN'));
    // update categories
    $mCategories = new Category();
    if (Params::getParam('submit') != '') {
        $categories = Params::getParam('categories');
        if (is_array($categories)) {
            foreach ($categories as $category_id) {
                $mCategories->update(array('b_enabled' => '1'), array('pk_i_id' => $category_id));
            }
        }
    }
    $aCategoriesToDelete = $mCategories->listWhere("a.b_enabled = 0");
    foreach ($aCategoriesToDelete as $aCategory) {
        $mCategories->deleteByPrimaryKey($aCategory['pk_i_id']);
    }
    $admin = $mAdmin->findByPrimaryKey(1);
    $data['s_email'] = $admin['s_email'];
    $data['admin_user'] = $admin['s_username'];
    $data['password'] = $password;
    return $data;
}
 /**
  * Controls and changes, if possible, category's active parameter if a product's active parameter changes.
  * 
  * @param array $ids_categories_array
  * @return 
  *
  */
 private function controlCategoriesForActivateTheir($ids_categories_array)
 {
     $size_array_categories = sizeof($ids_categories_array);
     for ($i = 0; $i < $size_array_categories; $i++) {
         $tmp = $ids_categories_array[$i];
         $category = new Category((int) $tmp["id"]);
         $array_of_ids_products = $category->getProductsWs();
         $size_array_products = sizeof($array_of_ids_products);
         $count = 0;
         for ($j = 0; $j < $size_array_products; $j++) {
             $array_prod = $array_of_ids_products[$j];
             $product = new Product((int) $array_prod["id"]);
             if (!$product->active) {
                 $count++;
             }
         }
         if ($count == $size_array_products) {
             $category->active = 0;
             $category->update();
         } else {
             $category->active = 1;
             $category->update();
         }
     }
 }
Example #12
0
function finish_installation()
{
    require_once LIB_PATH . 'osclass/helpers/hSecurity.php';
    require_once LIB_PATH . 'osclass/model/Admin.php';
    require_once LIB_PATH . 'osclass/model/Preference.php';
    require_once LIB_PATH . 'osclass/model/Category.php';
    require_once LIB_PATH . 'osclass/model/Item.php';
    require_once LIB_PATH . 'osclass/core/Params.php';
    require_once LIB_PATH . 'osclass/compatibility.php';
    require_once LIB_PATH . 'osclass/utils.php';
    $data = array();
    $password = osc_genRandomPassword();
    $mAdmin = new Admin();
    $admin_user = '******';
    $admin = $mAdmin->update(array('s_password' => sha1($password)), array('s_username' => $admin_user));
    $mPreference = Preference::newInstance();
    $mPreference->insert(array('s_section' => 'osclass', 's_name' => 'osclass_installed', 's_value' => '1', 'e_type' => 'BOOLEAN'));
    // update categories
    $mCategories = new Category();
    if (Params::getParam('submit') != '') {
        $categories = Params::getParam('categories');
        if (is_array($categories)) {
            foreach ($categories as $category_id) {
                $mCategories->update(array('b_enabled' => '1'), array('pk_i_id' => $category_id));
            }
        }
    }
    $aCategoriesToDelete = $mCategories->listWhere("a.b_enabled = 0");
    foreach ($aCategoriesToDelete as $aCategory) {
        $mCategories->deleteByPrimaryKey($aCategory['pk_i_id']);
    }
    $admin = $mAdmin->findByPrimaryKey(1);
    $data['s_email'] = $admin['s_email'];
    $data['admin_user'] = $admin_user;
    $data['password'] = $password;
    $body = 'Welcome ' . $mPreference->get('pageTitle') . ',<br/><br/>';
    $body .= 'Your OSClass installation at ' . WEB_PATH . ' is up and running. You can access to the administration panel with this data access:<br/>';
    $body .= '<ul>';
    $body .= '<li>username: '******'</li>';
    $body .= '<li>password: '******'</li>';
    $body .= '</ul>';
    $body .= 'Regards,<br/>';
    $body .= 'The <a href=\'http://osclass.org/\'>OSClass</a> team';
    $sitename = strtolower($_SERVER['SERVER_NAME']);
    if (substr($sitename, 0, 4) == 'www.') {
        $sitename = substr($sitename, 4);
    }
    require_once LIB_PATH . 'phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    $mail->CharSet = "utf-8";
    $mail->Host = "localhost";
    $mail->From = 'osclass@' . $sitename;
    $mail->FromName = 'OSClass';
    $mail->Subject = 'OSClass successfully installed!';
    $mail->AddAddress($admin['s_email'], 'OSClass administrator');
    $mail->Body = $body;
    $mail->AltBody = $body;
    if (!$mail->Send()) {
        echo $mail->ErrorInfo;
    }
    return $data;
}
 function test_update()
 {
     //arrange
     $name = "Business";
     $id = null;
     $test_category = new Category($name, $id);
     $test_category->save();
     $new_name = "Personal";
     //act
     $test_category->update($new_name);
     //assert
     $this->assertEquals("Personal", $test_category->getName());
 }
Example #14
0
echo "<div class='right-button-margin'>";
echo "<a href='read_categories.php' class='btn btn-primary pull-right'>";
echo "<span class='glyphicon glyphicon-list'></span> Read Categories";
echo "</a>";
echo "</div>";
// set ID property of product to be edited
$category->id = $category_id;
// read the details of category to be edited
$category->readOne();
// if the form was submitted
if ($_POST) {
    // set category property values
    $category->name = $_POST['name'];
    $category->description = $_POST['description'];
    // update the category
    if ($category->update()) {
        echo "<div class=\"alert alert-success alert-dismissable\">";
        echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>";
        echo "Category was updated.";
        echo "</div>";
    } else {
        echo "<div class=\"alert alert-danger alert-dismissable\">";
        echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>";
        echo "Unable to update category.";
        echo "</div>";
    }
}
?>
	
<!-- HTML form for updating a product -->
<form action='update_category.php?id=<?php 
Example #15
0
switch ($method) {
    case 'insert':
        if (isset($_POST['add_cat']) && !empty($_POST['add_cat'])) {
            $cat->name = $_POST['add_cat'];
            $cat->insert();
            header("location:../controle.php");
        } else {
            $_SESSTION['error'] = "please enter a valid name";
            header("location:../controle.php");
        }
        # code...
        break;
    case 'edit':
        if (isset($_POST['edit_cat']) && !empty($_POST['edit_cat'])) {
            $cat->name = $_POST['edit_cat'];
            $cat->update($id);
            echo "id=" . $id . " , name = " . $_POST['edit_cat'];
            header("location:../controle.php");
        } else {
            $_SESSTION['error'] = "please enter a valid name";
            echo "error";
            header("location:../controle.php");
        }
        # code...
        break;
    case 'delete':
        $cat->delete($id);
        header("location:../controle.php");
        # code...
        break;
    default:
<?php

include "../wp-load.php";
$id = $_POST['id'];
$parentId = $_POST['parentId'];
$name = $_POST['name'];
$description = $_POST['description'];
if (!$id) {
    $category = new Category($name, $description, $parentId);
    $id = $category->create();
} else {
    $db = new Database();
    $db->connect();
    $db->select("categories", "*", null, "id = " . $parentId);
    $parentCategory = $db->getResult(true);
    if ($parentCategory['parent_id'] != $id) {
        $category = new Category($name, $description, $parentId, $id);
        $category->update();
    } else {
        $db->select("categories", "*", null, "id = " . $id);
        $thisCategory = $db->getResult(true);
        $category = new Category($name, $description, $thisCategory['parent_id'], $id);
        $category->update();
    }
}
header("Location: /admin/categories/" . $id);
exit;
Example #17
0
     $input = Input::get(array('title', 'slug', 'description'));
     foreach ($input as $key => &$value) {
         $value = eq($value);
     }
     $validator = new Validator($input);
     $validator->check('title')->is_max(3, __('categories.title_missing'));
     if ($errors = $validator->errors()) {
         Input::flash();
         Notify::error($errors);
         return Response::redirect('admin/categories/edit/' . $id);
     }
     if (empty($input['slug'])) {
         $input['slug'] = $input['title'];
     }
     $input['slug'] = slug($input['slug']);
     Category::update($id, $input);
     Extend::process('category', $id);
     Notify::success(__('categories.updated'));
     return Response::redirect('admin/categories/edit/' . $id);
 });
 /*
     Add Category
 */
 Route::get('admin/categories/add', function () {
     $vars['token'] = Csrf::token();
     // extended fields
     $vars['fields'] = Extend::fields('category');
     return View::create('categories/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 Route::post('admin/categories/add', function () {
     $input = Input::get(array('title', 'slug', 'description'));
 function testUpdate()
 {
     $category_name = "music";
     $new_category = new Category($category_name);
     $new_category->save();
     $new_category->setCategoryName("concerts");
     $new_category->update();
     $result = Category::getAll();
     $this->assertEquals($new_category, $result[0]);
 }
 /**
  * Allows a user to edit a workshop category
  *
  */
 public function editAction()
 {
     $messages = array();
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->categoryId)) {
         throw new Ot_Exception_Input('msg-error-categoryIdNotSet');
     }
     $category = new Category();
     $thisCategory = $category->find($get->categoryId);
     if (is_null($thisCategory)) {
         throw new Ot_Exception_Data('msg-error-category');
     }
     $form = $category->form($thisCategory->toArray());
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             $data = array('categoryId' => $form->getValue('categoryId'), 'name' => $form->getValue('name'), 'description' => $form->getValue('description'));
             $category->update($data, null);
             $trigger = new Ot_Trigger();
             $data['accountId'] = Zend_Auth::getInstance()->getIdentity()->accountId;
             $trigger->setVariables($data);
             $trigger->dispatch('Category_Edit');
             $this->_helper->flashMessenger->addMessage('msg-info-categoryModified');
             $this->_helper->redirector->gotoUrl('/workshop/category/details/?categoryId=' . $form->getValue('categoryId'));
         } else {
             $messages[] = "msg-error-formSubmitProblem";
         }
     }
     $this->view->messages = $messages;
     $this->view->form = $form;
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.wysiwyg.js');
     $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.wysiwyg.css');
     $this->_helper->pageTitle('workshop-category-edit:title');
 }
<?php

require_once "util.php";
require_once "NTK/NTK.php";
require_once "DataBase/Category.php";
$db_action = var_get_post("db_action", "");
$category = new Category();
switch ($db_action) {
    case "new":
        $category->create(array(var_post("category_id", ""), var_post("name", ""), var_post("details", "")));
        break;
    case "edit":
        $category->update(var_post("category_id", ""), array(var_post("name", ""), var_post("details", "")));
        break;
    case "delete":
        $category->delete(var_get("category_id", ""));
        break;
}
Example #21
0
 * please see the COPYING and AUTHORS files
 * that were distributed with this source code.
 */
require_once __DIR__ . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/categories.tpl.html');
Auth::checkAuthentication();
$role_id = Auth::getCurrentRole();
if ($role_id < User::ROLE_MANAGER) {
    Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
@($prj_id = $_POST['prj_id'] ? $_POST['prj_id'] : $_GET['prj_id']);
$tpl->assign('project', Project::getDetails($prj_id));
if (@$_POST['cat'] == 'new') {
    $res = Category::insert();
    $tpl->assign('result', $res);
    Misc::mapMessages($res, array(1 => array(ev_gettext('Thank you, the category was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the category.'), Misc::MSG_ERROR), -2 => array(ev_gettext('Please enter the title for this new category.'), Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'update') {
    $res = Category::update();
    $tpl->assign('result', $res);
    Misc::mapMessages($res, array(1 => array('Thank you, the category was updated successfully.', Misc::MSG_INFO), -1 => array('An error occurred while trying to update the category.', Misc::MSG_ERROR), -2 => array('Please enter the title for this category.', Misc::MSG_ERROR)));
} elseif (@$_POST['cat'] == 'delete') {
    Category::remove();
}
if (@$_GET['cat'] == 'edit') {
    $tpl->assign('info', Category::getDetails($_GET['id']));
}
$tpl->assign('list', Category::getList($prj_id));
$tpl->displayTemplate();
Example #22
0
<?php

session_start();
require "../includes/checkPermission.php";
require "../../deny/connector.php";
require "class/class.Category.php";
require "../includes/injection.php";
$cateid = sqlInjection($_POST['cateID']);
$catename = sqlInjection($_POST['cateName']);
$cateparent = sqlInjection($_POST['cateParent']);
//echo $cateid." \"".$catename."\" ".$cateparent;
if ($catename == "") {
    $_SESSION['CATEEDIT'] = "<h4><font color=red face=Verdana>Tên loại sản phẩm không được để trống</font></h4>";
    //echo "<meta http-equiv='refresh' content='0;url=../admincp.php?opt=editcategory&cateID=".$cateid."'>";
    header("location: ../admincp.php?opt=editcategory&cateID={$cateid}");
    exit;
} else {
    $cate = new Category();
    $cate->update($cateid, $catename, $cateparent);
}
echo "<meta http-equiv='refresh' content='0;url=../admincp.php?opt=listcategory'>";
//header("location: ../admincp.php?opt=listcategory");
//exit();
Example #23
0
     }
     if (isset($_POST["cboBrand"])) {
         $oBrand = new Brand($_POST["cboBrand"]);
         $Category->setBrand($oBrand);
     }
     if ($control == Controls::Insert) {
         $Category->insert();
         $insert = true;
     } else {
         if ($control == Controls::Update) {
             if (isset($_POST["chkStatus"])) {
                 $Category->setStatus($_POST["chkStatus"]);
             } else {
                 $Category->setStatus(0);
             }
             $Category->update();
             $update = true;
         }
     }
 } else {
     if (isset($_GET["CatProID"]) && isset($_GET["control"])) {
         $control->setValue($_GET["control"]);
         $Category = Category::getCat($_GET["CatProID"]);
         if ($Category != null) {
             if ($control == Controls::Update) {
                 echo "<script> \$(function () { \$(window).load(function(){ \$('#modalCat').modal( { backdrop: 'static', keyboard: false }, 'show');})});</script>";
             } else {
                 if ($control == Controls::Delete) {
                     $Category->delete();
                     $delete = true;
                 }
        exit;
    } else {
        // update
        $obj = new Category($_REQUEST["id"]);
        $obj->CategoryName = $_REQUEST["category_name"];
        $obj->CategoryDescription = $_REQUEST["category_description"];
        $obj->BackgroundColor = $_REQUEST["background_color"];
        $obj->TitleHeading = $_REQUEST["title_heading"];
        $obj->SubtitleHeading = $_REQUEST["subtitle_heading"];
        $obj->ContactEmail = $_REQUEST["contact_email"];
        $is_active = false;
        if (isset($_REQUEST['is_active'])) {
            $is_active = true;
        }
        $obj->IsActive = $is_active;
        $obj->update();
        $obj->handleFileUploads();
        $obj->handleDropFileUploads($aDropFields[0], 'CategoryImageUrl');
        $obj->handleDropFileUploads($aDropFields[1], 'ExploreAllImageUrl');
        $obj->handleDropFileUploads($aDropFields[2], 'ExploreAllActiveImageUrl');
        $obj->handleDropFileUploads($aDropFields[3], 'TechnologyImageUrl');
        $obj->handleDropFileUploads($aDropFields[4], 'TechnologyActiveImageUrl');
        // redirect to listing list
        header("Location:category_list.php");
        exit;
    }
} else {
    if ($_REQUEST['mode'] == 'e') {
        //listing
        $cat = new Category($id);
        $category_name = $cat->CategoryName;
 /**
  * 更新国家信息
  * @access public
  */
 function update_save()
 {
     $id = get_post_value('id');
     $category_1 = get_post_value('category_1');
     $category_2_cn = get_post_value('category_2_cn');
     $category_2_th = get_post_value('category_2_th');
     $category_2_url = get_post_value('category_2_url');
     $orders = get_post_value('orders');
     if (!$this->verify($id)) {
         echo '<br> ' . $category_2_cn . ' 已存在,请核对后重新输入。<a href="javascript:history.go(-1)">返回</a><br>';
         return;
     }
     $field = array('category_1_id' => $category_1, 'category_2_cn' => trim($category_2_cn), 'category_2_th' => trim($category_2_th), 'category_2_url' => trim($category_2_url) == '' ? '#' : trim($category_2_url), 'orders' => $orders, 'created_name' => '');
     $m = new Category();
     $m->clear();
     $m->setTable('vcb_product_category_2');
     $m->setField($field);
     $m->setWhere('category_2_id', '=', $id);
     $data = $m->update();
     //返回
     echo '<br>操作成功,<a href="index" >返回</a><br>';
 }
Example #26
0
<?php

require_once './config.php';
$page = new AdminPage();
$category = new Category(['Settings' => $page->settings]);
$id = 0;
// Set the current action.
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
switch ($action) {
    case 'submit':
        $ret = $category->update($_POST["id"], $_POST["status"], $_POST["description"], $_POST["disablepreview"], $_POST["minsize"]);
        header("Location:" . WWW_TOP . "/category-list.php");
        break;
    case 'view':
    default:
        if (isset($_GET["id"])) {
            $page->title = "Category Edit";
            $id = $_GET["id"];
            $cat = $category->getByID($id);
            $page->smarty->assign('category', $cat);
        }
        break;
}
$page->smarty->assign('status_ids', array(Category::STATUS_ACTIVE, Category::STATUS_INACTIVE, Category::STATUS_DISABLED));
$page->smarty->assign('status_names', array('Yes', 'No', 'Disabled'));
$page->content = $page->smarty->fetch('category-edit.tpl');
$page->render();
 function save($p, $vars)
 {
     //print_r($p); return;
     //print_r($vars); return;
     //$user_id = $_SESSION['USERID'];
     //$from_ip = getenv ("REMOTE_ADDR");
     $c = new Category($this->db_conn);
     $c->getData($vars['id']);
     $old_photo = $c->photo;
     $c->name_cht = $vars['name_cht'];
     $c->name_eng = $vars['name_eng'];
     $c->brief_cht = $vars['brief_cht'];
     $c->brief_eng = $vars['brief_eng'];
     $c->desp_cht = $vars['desp_cht'];
     $c->desp_eng = $vars['desp_eng'];
     $c->vw_cht = $vars['vw_cht'];
     $c->vw_eng = $vars['vw_eng'];
     $c->hotspot_cht = $vars['hotspot_cht'];
     $c->hotspot_eng = $vars['hotspot_eng'];
     $c->seq = $vars['seq'];
     $c->code = $vars['code'];
     //$this->gotoURL("user.php?action=list");
     //上傳
     $uploaddir = HTML_ROOT_PATH . "photo/cat/" . $c->id . "/";
     if ($vars['photo_del'] == "Y") {
         $old_logo = "";
         $deletefile = $uploaddir . $old_logo;
         //舊圖圖檔路徑
         if (file_exists($deletefile)) {
             //檢查文件OR目錄是否存在
             unlink($deletefile);
             //刪除文件
             $c->photo = "";
             //資料庫檔案名清空
         }
     }
     if ($vars['photo']['name'] != "") {
         if (!is_dir($uploaddir)) {
             mkdir($uploaddir, 0777);
         }
         $pos = strrpos($vars['photo']['name'], ".");
         //查詢"."在$vars['logo']['name']最後一次出現位置 (取得檔名長度)
         $extension = strtolower(substr($vars['photo']['name'], $pos + 1));
         //返回$vars['logo']['name']從(檔名長度)加.開始  (取得檔案類型)
         $dst_file = "logo_" . $c->id . "." . $extension;
         //會員ID的圖檔名
         $dst_file_path = $uploaddir . $dst_file;
         //加上圖檔路徑目錄
         $photoname = $dst_file;
         //會員ID圖檔名塞進$photoname變數
         if ($old_logo != "") {
             $deletefile = $uploaddir . $old_photo;
             if (file_exists($deletefile)) {
                 unlink($deletefile);
                 $c->logo = "";
             }
         }
         $src_file = $vars['photo']['tmp_name'];
         $im = @imagecreatefromjpeg($vars['photo']['tmp_name']);
         //php從jpeg文件OR URL新建一圖象
         $imx = imagesx($im);
         //取圖寬
         $imy = imagesy($im);
         //取圖高
         $new_w = 400;
         $new_h = 400;
         if ($imx > $new_w || $imy > $new_h) {
             // 縮圖
             $src_file = resize_image($vars['photo']['tmp_name'], $src_file, $new_w, $new_h);
         }
         $photouploadfile = $uploaddir . $dst_file;
         if (copy($src_file, $photouploadfile)) {
             //logo圖檔複製到指定目錄
             $c->photo = $photoname;
             //print_r($photoname);                      //資料庫logo欄位寫進 會員ID的圖檔名
         } else {
             echo $photouploadfile . "<br>";
             echo "Possible Photo file upload attack!\n";
         }
     }
     $c->update();
     $this->gotoURL("category.php?action=list");
     //$this->gotoURL("category.php?action=show&id=".$c->id);
     //$this->browse($p);
 }
 public static function update($id, $data)
 {
     session_start();
     $headers = apache_request_headers();
     $token = $headers['X-Auth-Token'];
     if (!$headers['X-Auth-Token']) {
         header('Invalid CSRF Token', true, 401);
         return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Invalid CSRF Token / Bad Request / Unauthorized ... Please Login again'), JSON_PRETTY_PRINT);
     } else {
         if ($token != $_SESSION['form_token']) {
             header('Invalid CSRF Token', true, 401);
             return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Invalid CSRF Token / Bad Request / Unauthorized ... Please Login again'), JSON_PRETTY_PRINT);
         } else {
             if (!isset($data['category_name']) && empty($data['category_name'])) {
                 return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Category Name is required'), JSON_PRETTY_PRINT);
             } else {
                 if (!isset($data['time']) && empty($data['time'])) {
                     return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Time Limit for Quiz is required'), JSON_PRETTY_PRINT);
                     die;
                 } else {
                     $var = ["category_name" => $data['category_name'], "time" => $data['time']];
                     Category::update($id, $var);
                 }
             }
         }
     }
 }
Example #29
0
    private function updateCat()
    {
        $moduleName = Tools::getValue('moduleName');
        Db::getInstance()->execute('UPDATE
									' . _DB_PREFIX_ . 'category c
									INNER JOIN
									' . _DB_PREFIX_ . 'category c2
									ON
									c.id_parent = c2.`id_category_' . bqSQL($moduleName) . '`
									SET
									c.id_parent = c2.id_category
									WHERE c.`id_category_' . bqSQL($moduleName) . '` != 0');
        $category = new Category();
        $cats = $category->getSimpleCategories((int) Configuration::get('PS_LANG_DEFAULT'));
        foreach ($cats as $cat) {
            $cat = new Category((int) $cat['id_category']);
            $cat->level_depth = $cat->calcLevelDepth();
            $cat->update();
        }
    }
Example #30
0
<?php

/**
 * Created by PhpStorm.
 * User: nimzy
 * Date: 1/21/2016
 * Time: 12:09 AM
 */
require_once dirname(__FILE__) . '/../vendor/autoload.php';
//autoload packages
$db = new Database();
$category = new Category($db->conn);
if (!empty($_POST)) {
    //print_r($_POST);exit;
    foreach ($_POST as $field_name => $val) {
        //        //clean post values
        $field_userid = strip_tags(trim($field_name));
        $val = strip_tags(trim($val));
        //
        //        //from the fieldname:user_id we need to get user_id
        $split_data = explode(':', $field_userid);
        $category_id = $split_data[1];
        $field_name = $split_data[0];
        $category->update($field_name, $val, $category_id);
        echo "Field Succefully Updated!!";
    }
} else {
    echo "Invalid Requests";
}