예제 #1
0
 /**
  * It creates a new City object class ir if it has been created
  * before, it return the previous object
  * 
  * @access public
  * @since unknown
  * @return City 
  */
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #2
0
 public function processEditForm($new_item = array(), $files = array())
 {
     $param_name = 'new_item';
     Session::newInstance()->_setForm($param_name, $new_item);
     // keep values on session
     Session::newInstance()->_keepForm($param_name);
     $default_fields = array('gn_id' => NULL, 'gn_title' => '', 'gn_description' => '', 'gn_tags' => '', 'gn_lang' => osc_current_admin_locale());
     $new_item = array_merge($default_fields, $new_item);
     if (!$new_item['gn_title']) {
         throw new Exception(__('The title must not be empty', 'gz_news'));
     }
     if (!$new_item['gn_description']) {
         throw new Exception(__('The description must not be empty', 'gz_news'));
     }
     $dao = GzNewsDao::newInstance();
     if ($new_item['gn_id']) {
         $item_exists = $dao->findByPrimaryKey($new_item['gn_id']);
         if ($item_exists == FALSE) {
             throw new Exception(__('The new does not exists anymore', 'gz_news'));
         }
     }
     $success = $dao->save($new_item);
     if ($success) {
         if (!empty($files)) {
             $this->uploadFiles($success, $files);
         }
         Session::newInstance()->_dropKeepForm($param_name);
     }
     return $success;
 }
예제 #3
0
<?php

define('ABS_PATH', dirname(dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))))) . '/');
define('OC_ADMIN', true);
require_once ABS_PATH . 'oc-load.php';
if (osc_is_admin_user_logged_in() == FALSE) {
    die;
}
$model = new GzNewsModel();
$dao = GzNewsDao::newInstance();
$redirect_url = $_SERVER['HTTP_REFERER'];
$gn_id = (int) Params::getParam('gn_id');
$from_form = (bool) Params::getParam('from_form');
if ($from_form) {
    $redirect_url = GzNewsUtils::getAdminIndexUrl();
}
$success = $dao->deleteByPrimaryKey($gn_id);
if ($success) {
    $model->removeFiles($gn_id);
    osc_add_flash_ok_message(__('The item was deleted successfully', 'gz_news'), 'admin');
} else {
    osc_add_flash_error_message('There were a problem while deleting the item', 'admin');
}
$model->redirectTo($redirect_url);