Exemple #1
0
 /**
  * Show the profile of a student
  */
 public function view($params)
 {
     $this->setView('view.php');
     $is_logged = isset(User_Model::$auth_data);
     $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // If the user isn't logged in
     if (!$is_logged) {
         throw new ActionException('User', 'signin', array('redirect' => $_SERVER['REQUEST_URI']));
     }
     try {
         $student = $this->model->getInfo($params['username']);
         $post_model = new Post_Model();
         $this->setTitle(htmlspecialchars($student['firstname'] . ' ' . $student['lastname']));
         $this->set(array('student' => $student, 'groups' => isset($student['id']) ? Group_Model::getAuth((int) $student['id']) : array(), 'is_owner' => User_Model::$auth_data['username'] == $student['username'], 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin, 'username' => User_Model::$auth_data['username']));
         if ($is_student) {
             $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
         }
         // If the student is a user, we show their posts
         if (isset($student['id'])) {
             $category = isset($params['category']) ? $params['category'] : null;
             $category_model = new Category_Model();
             $this->set(array('posts' => $post_model->getPosts(array('restricted' => true, 'user_id' => (int) $student['id'], 'category_name' => $category, 'official' => false, 'show_private' => $is_student), Config::POST_DISPLAYED), 'categories' => $category_model->getAll(), 'current_category' => $category));
         }
     } catch (Exception $e) {
         throw new ActionException('Page', 'error404');
     }
 }
Exemple #2
0
 /**
  * Show the profile of a group
  */
 public function view($params)
 {
     $this->setView('view.php');
     try {
         $group = $this->model->getInfoByName($params['group']);
         $this->set('group', $group);
     } catch (Exception $e) {
         throw new ActionException('Page', 'error404');
     }
     $this->setTitle(__('GROUP_TITLE', array('group' => htmlspecialchars($group['name']))));
     $is_logged = isset(User_Model::$auth_data);
     $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     $category = isset($params['category']) ? $params['category'] : null;
     $category_model = new Category_Model();
     $post_model = new Post_Model();
     $this->set(array('is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin, 'categories' => $category_model->getAll(), 'current_category' => $category, 'posts' => $post_model->getPosts(array('restricted' => true, 'group_id' => (int) $group['id'], 'category_name' => $category, 'official' => $is_logged ? null : true, 'show_private' => $is_student), Config::POST_DISPLAYED)));
     // Events
     $event_model = new Event_Model();
     $this->set(array('events' => $event_model->getByMonth((int) date('Y'), (int) date('n'), array('group_id' => (int) $group['id'], 'official' => $is_logged ? null : true, 'show_private' => $is_student)), 'calendar_month' => (int) date('n'), 'calendar_year' => (int) date('Y')));
     // If the user is logged
     if ($is_logged) {
         $this->set(array('username' => User_Model::$auth_data['username'], 'groups_auth' => Group_Model::getAuth()));
     }
     if ($is_student) {
         $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
     }
 }
    /**
     * Creates the required database tables for the sharing module
     */
    public function run_install()
    {
        // Create the database tables
        // Include the table_prefix
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_site`\n\t\t\t(\n\t\t\t\t`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`site_name` varchar(150) NOT NULL COMMENT 'name that appears on the front end',\n\t\t\t\t`site_url` varchar(255) NOT NULL COMMENT 'url of the deployment to share with',\n\t\t\t\t`site_color` varchar(20) DEFAULT 'CC0000' COMMENT 'color that shows the shared reports',\n\t\t\t\t`site_active` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'sharing active or inactive ',\n\t\t\t\t`share_categories` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'sharing active or inactive ',\n\t\t\t\t`share_reports` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'sharing active or inactive ',\n\t\t\t\t`site_username` varchar(150) NOT NULL COMMENT 'username for the remote site',\n\t\t\t\t`site_password` varchar(150) NOT NULL COMMENT 'password for the remote site',\n\t\t\t\tPRIMARY KEY (id)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores sites we are getting shared reports from'\n\t\t\t");
        $result = $this->db->query("SHOW COLUMNS FROM `sharing_site` LIKE 'site_username';");
        if ($result->count() == 0) {
            $this->db->query('
					ALTER TABLE `sharing_site`
						ADD COLUMN `site_username` varchar(150) NOT NULL COMMENT \'username for the remote site\',
						ADD COLUMN `site_password` varchar(150) NOT NULL COMMENT \'password for the remote site\'
				');
        }
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident`\n\t\t\t(\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`location_id` bigint(20) unsigned NOT NULL,\n\t\t\t\t`sharing_site_id` INT UNSIGNED NOT NULL,\n\t\t\t\t`remote_incident_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`updated` datetime DEFAULT NULL,\n\t\t\t\t`incident_title` varchar(255) NOT NULL COMMENT 'title of the report',\n\t\t\t\t`incident_description` longtext,\n\t\t\t\t`incident_date` datetime DEFAULT NULL,\n\t\t\t\t`incident_mode` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1 - WEB, 2 - SMS, 3 - EMAIL, 4 - TWITTER',\n\t\t\t\t`incident_active` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t\t`incident_verified` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t\tPRIMARY KEY (id),\n\t\t\t\tKEY `location_id` (`location_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared reports'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_category` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  `category_id` int(11) unsigned NOT NULL DEFAULT '5',\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  UNIQUE KEY `sharing_incident_category_ids` (`sharing_incident_id`,`category_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared reports categories'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_media` (\n\t\t\t  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  `media_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  UNIQUE KEY `sharing_incident_media_ids` (`sharing_incident_id`,`media_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared reports media'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_comment` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  `comment_id` int(11) unsigned NOT NULL DEFAULT '5',\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  UNIQUE KEY `sharing_incident_comment_ids` (`sharing_incident_id`,`comment_id`)\n\t\t\t) ENGINE=MyISAM AUTO_INCREMENT=14064 DEFAULT CHARSET=utf8 COMMENT='Stores shared reports comments'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_category`\n\t\t\t(\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`sharing_site_id` INT UNSIGNED NOT NULL,\n\t\t\t\t`category_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`remote_category_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`updated` datetime DEFAULT NULL,\n\t\t\t\tPRIMARY KEY (id),\n\t\t\t  UNIQUE KEY `category_id` (`category_id`),\n\t\t\t  UNIQUE KEY `remote_category_id` (`sharing_site_id`,`remote_category_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared categories'\n\t\t\t");
        // Create view for querying
        $this->db->query("\n\t\t\tCREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW `sharing_combined_incident` AS\n\t\t\t\tSELECT `incident`.`id` AS `id`,\n\t\t\t\t\t`incident`.`incident_title` AS `incident_title`,\n\t\t\t\t\t`incident`.`incident_description` AS `incident_description`,\n\t\t\t\t\t`incident`.`incident_date` AS `incident_date`,\n\t\t\t\t\t`incident`.`incident_mode` AS `incident_mode`,\n\t\t\t\t\t`incident`.`location_id` AS `location_id`,\n\t\t\t\t\t`incident`.`incident_active` AS `incident_active`,\n\t\t\t\t\t`incident`.`incident_verified` AS `incident_verified`,\n\t\t\t\t\t'main' AS `source`,\n\t\t\t\t\tNULL AS `source_url`\n\t\t\t\tFROM `incident`\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\t`sharing_incident`.`id` AS `id`,\n\t\t\t\t\t`sharing_incident`.`incident_title` AS `incident_title`,\n\t\t\t\t\t`sharing_incident`.`incident_description` AS `incident_description`,\n\t\t\t\t\t`sharing_incident`.`incident_date` AS `incident_date`,\n\t\t\t\t\t`sharing_incident`.`incident_mode` AS `incident_mode`,\n\t\t\t\t\t`sharing_incident`.`location_id` AS `location_id`,\n\t\t\t\t\t`sharing_incident`.`incident_active` AS `incident_active`,\n\t\t\t\t\t`sharing_incident`.`incident_verified` AS `incident_verified`,\n\t\t\t\t\t`sharing_incident`.`sharing_site_id` AS `source`,\n\t\t\t\t\t`sharing_site`.`site_url` AS `source_url`\n\t\t\t\tFROM `sharing_incident`\n\t\t\t\tLEFT JOIN `sharing_site`\n\t\t\t\t\tON (`sharing_incident`.`sharing_site_id` = `sharing_site`.`id`)\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW `sharing_combined_incident_category` AS\n\t\t\t\tSELECT `incident_category`.`incident_id` AS `incident_id`,\n\t\t\t\t\tNULL AS `sharing_incident_id`,\n\t\t\t\t\t`incident_category`.`category_id` AS `category_id`\n\t\t\t\tFROM `incident_category`\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\tNULL AS `incident_id`,\n\t\t\t\t\t`sharing_incident_category`.`sharing_incident_id` AS `sharing_incident_id`,\n                  `sharing_incident_category`.`category_id` AS `category_id`\n\t\t\t\tFROM `sharing_incident_category`\n\t\t\t");
        //Dump the sharing scheduler item from bundled SQL dump file
        $this->db->query("DELETE FROM `" . Kohana::config('database.default.table_prefix') . "scheduler` where scheduler_name = 'Sharing' ");
        // Add sharing in to scheduler table
        $this->db->query("INSERT IGNORE INTO `" . Kohana::config('database.default.table_prefix') . "scheduler`\n\t\t\t\t(`scheduler_name`,`scheduler_last`,`scheduler_weekday`,`scheduler_day`,`scheduler_hour`,`scheduler_minute`,`scheduler_controller`,`scheduler_active`) VALUES\n\t\t\t\t('Sharing','0','-1','-1','-1','-1','s_sharing','1')");
        // Add Other category to the categories list (if it doesn't exist already)
        $categoryname = "Other";
        $other_category = ORM::factory('category')->where('category_title', $categoryname)->where('parent_id', 0)->find();
        $current_other_category_id = Settings_Model::get_setting('sharing_other_category_id');
        if ($other_category->loaded && empty($current_other_category_id)) {
            // We already have a category "Other", save setting
            Settings_Model::save_setting('sharing_other_category_id', $other_category->id);
        } else {
            // No category named "Other". Do we have an id save though (maybe it's been renamed)
            $category = ORM::factory('Category', Settings_Model::get_setting('sharing_other_category_id'));
            if (!$category->loaded) {
                $this->notices[] = Kohana::lang('import.new_category') . $categoryname;
                $category = new Category_Model();
                $category->category_title = $categoryname;
                // We'll use grey for now. Maybe something random?
                $category->category_color = '000000';
                $category->category_visible = 1;
                // FIXIT: We need to make this zero for non-central deployments?
                $category->category_trusted = 1;
                // Trusted - can't delete
                $category->category_description = "Category with reports that couldn't be categorised from other deployments";
                //FIXIT: need to l10n this;
                $category->category_position = ORM::factory('category')->count_all();
                $category->save();
                Settings_Model::save_setting('sharing_other_category_id', $category->id);
            }
        }
    }
Exemple #4
0
 public function insert($category, $username, $value)
 {
     $cat = new Category_Model();
     $category = $cat->get_id($category);
     $user = new User_Model();
     $username = $user->get_id($username);
     $results = $this->db->query("INSERT INTO results SET cat_id = ?, user_id = ?, value = ?, result_date = NOW()", $category, $username, $value);
     if ($results) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Test the is_valid_category method in Category_Model using a 
  * valid category id
  *
  * @test
  * @dataProvider providerIsValidCategory
  * @param int $valid_category_id  ID of a category exisitng in the database
  * @param int $invalid_category_id ID of a non-existent/non-numeric category
  */
 public function testIsValidCategory($valid_category_id, $invalid_category_id)
 {
     // Test existence of valid category
     $this->assertEquals(TRUE, Category_Model::is_valid_category($valid_category_id));
     // Assert invalidity and non-existence of invalid category
     $this->assertEquals(FALSE, Category_Model::is_valid_category($invalid_category_id));
 }
Exemple #6
0
 public function index()
 {
     $this->template->content = new View('mobile/main');
     // Get 10 Most Recent Reports
     $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->with('location')->find_all();
     // Get all active top level categories
     $parent_categories = array();
     $parentCategoryId = 0;
     foreach (Category_Model::getCategories($parentCategoryId) as $category) {
         // Get The Children
         $children = array();
         foreach ($category->children as $child) {
             $children[$child->id] = array($child->category_title, $child->category_color, $child->category_image, $this->_category_count($child->id));
         }
         // Put it all together
         $parent_categories[$category->id] = array($category->category_title, $category->category_color, $category->category_image, $this->_category_count($category->id), $children);
         if ($category->category_trusted) {
             // Get Trusted Category Count
             $trusted = ORM::factory("incident")->join("incident_category", "incident.id", "incident_category.incident_id")->where("category_id", $category->id);
             if (!$trusted->count_all()) {
                 unset($parent_categories[$category->id]);
             }
         }
     }
     $this->template->content->categories = $parent_categories;
     // Get RSS News Feeds
     $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all();
 }
Exemple #7
0
 /**
  * 更新联系人所在分组
  * @param int $id
  * @param string $type
  */
 private function _contact_to_group($id, $type = 'add')
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, Kohana::lang('contact.method_not_exist'));
     }
     $id = (int) $id;
     if ($type == 'add' and empty($id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_id_empty'));
     }
     if (!empty($id) and !$this->model->get_category_name($this->user_id, $id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_not_exist'));
     }
     $data = $this->get_data();
     $ids = !empty($data['ids']) ? explode(',', $data['ids']) : array();
     if (empty($ids)) {
         $this->send_response(400, NULL, Kohana::lang('contact.contact_ids_empty'));
     }
     $result = array();
     $update_ids = $this->model->move_contact_category($this->user_id, $id, $ids, $type);
     if ($update_ids) {
         $now = api::get_now_time();
         foreach ($update_ids as $id) {
             $result[] = array('id' => (int) $id, 'modified_at' => $now);
         }
     }
     $this->send_response(200, $result, '', FALSE);
 }
Exemple #8
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new Category_Model();
     }
     return self::$instance;
 }
Exemple #9
0
 public static function GetPanel()
 {
     $tpl = new Template();
     $items = Category_Model::GetCategories();
     $tpl->SetParam('cart', $_SESSION['cart']);
     return $tpl->Fetch('templates/cart/cart-panel.tpl');
 }
Exemple #10
0
 /**
  * 单例模式
  * @return Category_Model
  */
 public static function &instance()
 {
     if (!isset(self::$instance)) {
         // Create a new instance
         self::$instance = new Category_Model();
     }
     return self::$instance;
 }
Exemple #11
0
 public function document()
 {
     $allDepartments = Department_Model::getAllDepartments();
     $data = array('pageTitle' => 'Document Builder', 'bodyClass' => 'edit', 'builder' => 'document', 'headerModules' => json_decode($this->builder->getModules('header')), 'bodyModules' => json_decode($this->builder->getModules('body')), 'footerModules' => json_decode($this->builder->getModules('footer')), 'draftModules' => json_decode($this->builder->getDraftModules()), 'unpublishedModules' => json_decode($this->builder->getUnpublishedModules()), 'allCategories' => Category_Model::getAllCategories(), 'allDepartments' => Department_Model::getAllDepartments());
     $this->load->view('templates/header', $data);
     $this->load->view('builder/inner_navbar_view');
     $this->load->view('builder/document_builder_view');
     $this->load->view('templates/footer');
 }
Exemple #12
0
 public function update($category)
 {
     $cat = new Category_Model();
     if ($cat->category_exists($category) and apiler::is_authorized()) {
         $xml = apiler::get_xml();
         $result = new Result_Model();
         if ($result->insert($category, $_SERVER['PHP_AUTH_USER'], $xml['value'])) {
             print "OK";
             die;
         } else {
             header("HTTP/1.1 400 Bad Request");
             echo "Invalid request";
             die;
         }
     } else {
         header("HTTP/1.0 404 Not Found");
         die('Category not found or not authorized');
     }
 }
Exemple #13
0
 public function deleteCategory()
 {
     $post = $this->input->post();
     if (!$this->userObj->admin) {
         $error = array('status' => 'error', 'msg' => 'You cannot delete this department.');
         echo json_encode($error);
         exit;
     }
     Category_Model::deleteCategory($post['assignId'], $post['deleteId']);
 }
Exemple #14
0
 public function loadData()
 {
     $currentUserDept = $this->session->department;
     //CHM - Pull in the sub-select values
     if (!($tName = $this->cache->get('udfFields'))) {
         $query = $this->db->select('table_name')->where('field_type', 4)->get('udf');
         $tName = array();
         foreach ($query->result() as $data) {
             $explodeV = explode('_', $data->table_name);
             $tName[] = $explodeV[2];
             $i++;
         }
         $this->cache->save('udfFields', $tName, 600);
     }
     // We need to set a form value for the current user so that
     // they can be pre-selected on the form
     $availUsers = User_Model::getAllUsers();
     $usersArray = array();
     foreach ($availUsers as $availUser) {
         if ($availUser->id == $this->session->id) {
             $availUser->selected = 'checked';
         } else {
             $availUser->selected = '';
         }
         array_push($usersArray, $availUser);
     }
     // We need to set a form value for the current department so that
     // it can be pre-selected on the form
     $availDepartments = Department_Model::getAllDepartments();
     $departmentsArray = array();
     foreach ($availDepartments as $availDepartment) {
         if ($availDepartment->id == $currentUserDept) {
             $availDepartment->selected = 'checked';
         } else {
             $availDepartment->selected = '';
         }
         array_push($departmentsArray, $availDepartment);
     }
     $availCategories = Category_Model::getAllCategories();
     $catsArray = array();
     foreach ($availCategories as $availCategory) {
         array_push($catsArray, $availCategory);
     }
     //////Populate department perm list/////////////////
     $deptPermsArray = array();
     foreach ($departmentsArray as $dept) {
         $availDeptPerms = new stdClass();
         $availDeptPerms->name = $dept->name;
         $availDeptPerms->id = $dept->id;
         array_push($deptPermsArray, $availDeptPerms);
     }
     $data = array('tName' => $tName, 'availUsers' => $usersArray, 'allDepartments' => $availDepartments, 'deptPerms' => $departmentsArray, 'availCategories' => $catsArray);
     return json_encode($data);
 }
Exemple #15
0
 /**
  * Returns an array with all categories
  *
  * @return array
  */
 public function getAll()
 {
     if (isset(self::$categories)) {
         return self::$categories;
     }
     if ($categories = Cache::read('categories')) {
         return $categories;
     }
     self::$categories = $this->createQuery()->fields('id', 'name', 'url_name')->order(array('order', 'ASC'))->select();
     Cache::write('categories', self::$categories, 3600);
     return self::$categories;
 }
Exemple #16
0
 public function index($params)
 {
     $this->setView('index.php');
     $is_logged = isset(User_Model::$auth_data);
     $is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     $category = isset($params['category']) ? $params['category'] : null;
     $category_model = new Category_Model();
     $this->set(array('is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin, 'categories' => $category_model->getAll(), 'current_category' => $category));
     // If the user is logged
     if ($is_logged) {
         $this->set(array('username' => User_Model::$auth_data['username'], 'groups_auth' => Group_Model::getAuth(), 'posts' => $this->model->getPosts(array('restricted' => true, 'official' => false, 'category_name' => $category, 'show_private' => $is_student), Config::POST_DISPLAYED)));
     }
     // If the user is a student
     if ($is_student) {
         $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
     }
     // Official posts
     $this->set('official_posts', $this->model->getPosts(array('restricted' => true, 'official' => true, 'category_name' => $category, 'show_private' => $is_student), Config::POST_DISPLAYED));
     // Events
     $event_model = new Event_Model();
     $this->set(array('events' => $event_model->getByMonth((int) date('Y'), (int) date('n'), array('official' => $is_logged ? null : true, 'show_private' => $is_student)), 'calendar_month' => (int) date('n'), 'calendar_year' => (int) date('Y')));
 }
Exemple #17
0
 public function page($page_no = 1)
 {
     $items_per_page = 2;
     $cat_id = 2;
     $offset = ($page_no - 1) * $items_per_page;
     $limit = $items_per_page;
     $category = new Category_Model($cat_id);
     //$category = ORM::factory('category')->with('catagories_description')->find($cat_id); //without the lazy loading
     echo $category->name . '<br>';
     echo $category->catagories_description->description . '<br>';
     $catalog_list = $category->limit($limit, $offset)->products;
     //$catalog_list = $category->limit($limit, $offset)->like('products.name', 'ca')->products;
     //$catalog_list = $category->limit($limit, $offset)->where('product_id >', 1)->products;
     $catalog_total = $category->count_last_query();
     echo 'this category has ' . $catalog_total . ' related products';
     foreach ($catalog_list as $p) {
         echo $p->name . '<br>';
         echo $p->products_description->description . '<br>';
         print_r($p->attributes);
     }
     $pagination = new Pagination(array('uri_segment' => 'page', 'total_items' => $catalog_total, 'items_per_page' => $items_per_page, 'style' => 'classic', 'auto_hide' => TRUE));
     echo $pagination->render();
     $profile = new Profiler();
 }
Exemple #18
0
 public function categories($id = null)
 {
     if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
         return Category_Model::DeleteCategory($id);
     }
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $data = json_decode(file_get_contents("php://input"), true);
         return Category_Model::CreateCategory($data);
     }
     if ($_SERVER['REQUEST_METHOD'] == "PUT") {
         $data = json_decode(file_get_contents("php://input"), true);
         return Category_Model::UpdateCategory($data, $id);
     }
     if (isset($id)) {
         return Category_Model::GetCategoryById($id);
     }
     return Category_Model::GetCategories();
 }
Exemple #19
0
 /**
  * Generate geojson
  * 
  * @param string $type type of geojson to generate. Valid options are: 'clusters' and 'markers'
  **/
 protected function geojson($type)
 {
     $color = Kohana::config('settings.default_map_all');
     $icon = "";
     $markers = FALSE;
     if (Kohana::config('settings.default_map_all_icon_id')) {
         $icon_object = ORM::factory('media')->find(Kohana::config('settings.default_map_all_icon_id'));
         $icon = url::convert_uploaded_to_abs($icon_object->media_medium);
     }
     // Category ID
     $category_id = (isset($_GET['c']) and intval($_GET['c']) > 0) ? intval($_GET['c']) : 0;
     // Get the category colour
     if (Category_Model::is_valid_category($category_id)) {
         // Get the color & icon
         $cat = ORM::factory('category', $category_id);
         $color = $cat->category_color;
         $icon = "";
         if ($cat->category_image) {
             $icon = url::convert_uploaded_to_abs($cat->category_image);
         }
     }
     $params = array('color' => $color, 'icon' => $icon);
     Event::run('ushahidi_filter.json_alter_params', $params);
     $color = $params['color'];
     $icon = $params['icon'];
     // Run event ushahidi_filter.json_replace_markers
     // This allows a plugin to completely replace $markers
     // If markers are added at this point we don't bother fetching incidents at all
     Event::run('ushahidi_filter.json_replace_markers', $markers);
     // Fetch the incidents
     if (!$markers) {
         $markers = (isset($_GET['page']) and intval($_GET['page']) > 0) ? reports::fetch_incidents(TRUE) : reports::fetch_incidents();
     }
     // Run event ushahidi_filter.json_alter_markers
     // This allows a plugin to alter $markers
     // Plugins can add or remove markers as needed
     Event::run('ushahidi_filter.json_alter_markers', $markers);
     // Get geojson features array
     $function = "{$type}_geojson";
     $json_features = $this->{$function}($markers, $category_id, $color, $icon);
     $this->render_geojson($json_features);
 }
Exemple #20
0
 function reports()
 {
     $this->template->content = new View('admin/stats_reports');
     $this->template->content->title = 'Report Stats';
     // Retrieve Current Settings
     $settings = ORM::factory('settings', 1);
     $this->template->content->stat_id = $settings->stat_id;
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     // Report Data
     $data = Stats_Model::get_report_stats();
     $reports_chart = new protochart();
     $options = array('pies' => array('show' => 'true'), 'legend' => array('show' => 'true'));
     // Grab category data
     $cats = Category_Model::categories();
     $report_data = array();
     foreach ($data['category_counts'] as $category_id => $count) {
         $category_name = $cats[$category_id]['category_title'];
         $report_data[$category_name] = $count;
         $colors[$category_name] = $cats[$category_id]['category_color'];
     }
     $this->template->content->reports_chart = $reports_chart->chart('reports', $report_data, $options, $colors);
     $report_status_chart = new protochart();
     foreach ($data['verified_counts'] as $ver_or_un => $arr) {
         if (!isset($report_staus_data[$ver_or_un][0])) {
             $report_staus_data[$ver_or_un][0] = 0;
         }
         foreach ($arr as $count) {
             $report_staus_data[$ver_or_un][0] += $count;
         }
     }
     foreach ($data['approved_counts'] as $app_or_un => $arr) {
         if (!isset($report_staus_data[$app_or_un][0])) {
             $report_staus_data[$app_or_un][0] = 0;
         }
         foreach ($arr as $count) {
             $report_staus_data[$app_or_un][0] += $count;
         }
     }
     $this->template->content->report_status_chart = $report_status_chart->chart('report_status', $report_staus_data, $options);
 }
Exemple #21
0
 public function editValidate($data = array())
 {
     $getCategory = $this->getId('', $data['name']);
     //check category exists
     if ($getCategory) {
         if (!empty($data['id'])) {
             // Case : Edit User
             if ($getCategory['id'] != $data['id']) {
                 self::$error['name'] = 'CategoryName already exists !Please enter a different CategoryName!';
             }
         } else {
             // Case : Add User
             self::$error['name'] = 'CategoryName already exists !Please enter a different CategoryName!';
         }
     }
     $dataValidate = array('name' => $data['name']);
     $this->validate->dataValidate($dataValidate);
     //Merge 2 error array
     self::$error = array_merge($this->validate->getError(), self::$error);
     if (!empty(self::$error['name'])) {
         return false;
     }
     return true;
 }
Exemple #22
0
<?php

require 'admin_init.php';
login();
//删除单个文章
if (isset($_GET['post_id'])) {
    $post_id = $_GET['post_id'];
    Post_Model::getInstance()->deleteLog($post_id);
} elseif (isset($_GET['post_ids'])) {
    $ids = explode(',', $_GET['post_ids']);
    foreach ($ids as $id) {
        Post_Model::getInstance()->deleteLog($id);
    }
} elseif (isset($_GET['term_id'])) {
    Category_Model::getInstance()->deleteTerm($_GET['term_id']);
} elseif (isset($_GET['term_ids'])) {
    $ids = explode(',', $_GET['term_ids']);
    foreach ($ids as $id) {
        Category_Model::getInstance()->deleteTerm($id);
    }
}
Exemple #23
0
 /**
  * Gets the list of categories from the database as an array
  *
  * @param int $category_id Database id of the category
  * @param string $local Localization to use
  * @return array
  */
 public static function categories($category_id = NULL)
 {
     if (!isset(self::$categories)) {
         $categories = ORM::factory('category')->find_all();
         self::$categories = array();
         foreach ($categories as $category) {
             self::$categories[$category->id]['category_id'] = $category->id;
             self::$categories[$category->id]['category_title'] = $category->category_title;
             self::$categories[$category->id]['category_description'] = $category->category_description;
             self::$categories[$category->id]['category_color'] = $category->category_color;
             self::$categories[$category->id]['category_image'] = $category->category_image;
             self::$categories[$category->id]['category_image_thumb'] = $category->category_image_thumb;
         }
     }
     if ($category_id) {
         return isset(self::$categories[$category_id]) ? array($category_id => self::$categories[$category_id]) : FALSE;
     }
     return self::$categories;
 }
Exemple #24
0
 /**
  * Displays all reports.
  */
 public function index()
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports');
     // Filter By Category
     $category_filter = isset($_GET['c']) && !empty($_GET['c']) ? "category_id = " . $_GET['c'] : " 1=1 ";
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => ORM::factory('incident')->join('incident_category', 'incident.id', 'incident_category.incident_id')->where('incident_active', '1')->where($category_filter)->count_all()));
     $incidents = ORM::factory('incident')->select('DISTINCT incident.*')->join('incident_category', 'incident.id', 'incident_category.incident_id')->where('incident_active', '1')->where($category_filter)->groupby('incident.id')->orderby('incident_date', 'desc')->find_all((int) Kohana::config('settings.items_per_page'), $pagination->sql_offset);
     $this->template->content->incidents = $incidents;
     //Set default as not showing pagination. Will change below if necessary.
     $this->template->content->pagination = '';
     // Pagination and Total Num of Report Stats
     if ($pagination->total_items == 1) {
         $plural = '';
     } else {
         $plural = 's';
     }
     if ($pagination->total_items > 0) {
         $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1;
         $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page'));
         if ($total_pages > 1) {
             // If we want to show pagination
             $this->template->content->pagination_stats = '(Showing ' . $current_page . ' of ' . $total_pages . ' pages of ' . $pagination->total_items . ' report' . $plural . ')';
             $this->template->content->pagination = $pagination;
         } else {
             // If we don't want to show pagination
             $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')';
         }
     } else {
         $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')';
     }
     $icon_html = array();
     $icon_html[1] = "<img src=\"" . url::base() . "media/img/image.png\">";
     //image
     $icon_html[2] = "<img src=\"" . url::base() . "media/img/video.png\">";
     //video
     $icon_html[3] = "";
     //audio
     $icon_html[4] = "";
     //news
     $icon_html[5] = "";
     //podcast
     //Populate media icon array
     $this->template->content->media_icons = array();
     foreach ($incidents as $incident) {
         $incident_id = $incident->id;
         if (ORM::factory('media')->where('incident_id', $incident_id)->count_all() > 0) {
             $medias = ORM::factory('media')->where('incident_id', $incident_id)->find_all();
             //Modifying a tmp var prevents Kohona from throwing an error
             $tmp = $this->template->content->media_icons;
             $tmp[$incident_id] = '';
             foreach ($medias as $media) {
                 $tmp[$incident_id] .= $icon_html[$media->media_type];
                 $this->template->content->media_icons = $tmp;
             }
         }
     }
     // Category Title, if Category ID available
     $category_id = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : "0";
     $category = ORM::factory('category')->find($category_id);
     $this->template->content->category_title = $category->loaded ? $category->category_title : "";
     // BEGIN CHART CREATION
     //   Note: The reason this code block is so long is because protochart
     //         doesn't seem to handle bar charts in time mode so well. The
     //         bars show up as skinny lines because it uses the timestamp
     //         to determine location on the graph, which doesn't give the
     //         bar much wiggle room in just a few hundred pixels.
     // Create protochart
     $this->template->header->protochart_enabled = TRUE;
     $report_chart = new protochart();
     // FIXME: Perhaps instead of grabbing the report stats again, we can
     //        get what we need from above so we can cut down on database
     //        calls. It will take playing with the incident model to get
     //        all of the data we need, though.
     // Report Data
     $data = Stats_Model::get_report_stats(true);
     // Grab category data
     $cats = Category_Model::categories();
     $highest_count = 1;
     $report_data = array();
     $tick_string_array = array();
     foreach ($data['category_counts'] as $category_id => $count_array) {
         // Does this category exist locally any more?
         if (isset($cats[$category_id])) {
             $category_name = $cats[$category_id]['category_title'];
             $colors[$category_name] = $cats[$category_id]['category_color'];
             $i = 1;
             foreach ($count_array as $time => $count) {
                 $report_data[$category_name][$i] = $count;
                 // The highest count will determine the number of ticks on the y-axis
                 if ($count > $highest_count) {
                     $highest_count = $count;
                 }
                 // This statement sets us up so we can convert the key to a date
                 if (!isset($tick_represents[$i])) {
                     $tick_represents[$i] = $time;
                     // Save name
                     $tick_string_array[$i] = date('M d', $time);
                 }
                 $i++;
             }
         }
     }
     $highest_count += 1;
     // This javascript function will take the integer index and convert it to a readable date
     $tickFormatter = "function (val, axis)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t    switch(val){";
     foreach ($tick_string_array as $i => $date_string) {
         $tickFormatter .= "case {$i}:\n\t\t\t\t\t\t    \t\treturn '{$date_string}';";
     }
     $tickFormatter .= "default:\n\t\t\t\t\t\t    \t\treturn '';\n\t\t\t\t\t\t    }\n\t\t\t\t\t\t    return 'sup';\n\t\t\t\t\t\t  }";
     $options = array('bars' => array('show' => 'true'), 'xaxis' => array('min' => 0, 'max' => count($tick_string_array) + 1, 'tickFormatter' => $tickFormatter), 'yaxis' => array('tickSize' => 1, 'max' => $highest_count, 'tickDecimals' => 0), 'legend' => array('show' => 'true', 'noColumns' => 3), 'grid' => array('drawXAxis' => 'false'));
     if (count($report_data) == 0) {
         // Don't show a chart if there's no data
         $this->template->content->report_chart = '';
     } else {
         // Show chart
         $width = 900;
         $height = 100;
         $this->template->content->report_chart = $report_chart->chart('reports', $report_data, $options, $colors, $width, $height);
     }
 }
    /**
     * Get incidents within a certain lat,lon bounding box
     *
     * @param sw is the southwest lat,lon of the box
     * @param ne is the northeast lat,lon of the box
     * @param c is the categoryid
     */
    private function _get_incidents_by_bounds($sw, $ne, $c = 0)
    {
		// Get location_ids if we are to filter by location
		$location_ids = array();

		// Break apart location variables, if necessary
		$southwest = array();
		if (isset($sw))
		{
			$southwest = explode(",",$sw);
		}

		$northeast = array();
		if (isset($ne))
		{
			$northeast = explode(",",$ne);
		}

		if ( count($southwest) == 2 AND count($northeast) == 2 )
		{
			$lon_min = (float) $southwest[0];
			$lon_max = (float) $northeast[0];
			$lat_min = (float) $southwest[1];
			$lat_max = (float) $northeast[1];

			$query = 'SELECT id FROM '.$this->table_prefix.'location WHERE latitude >='.$lat_min.' AND latitude <='.$lat_max.' AND longitude >='.$lon_min.' AND longitude <='.$lon_max;

			$items = $this->db->query($query);

			foreach ( $items as $item )
			{
				$location_ids[] =  $item->id;
			}
		}
		
		$location_id_in = '1=1';
		
		if (count($location_ids) > 0)
		{
			$location_id_in = 'l.id IN ('.implode(',',$location_ids).')';
		}
		
		$where = ' WHERE i.incident_active = 1 AND '.$location_id_in.' ';

		// Fix for pulling categories using the bounding box
		// Credits to Antonoio Lettieri http://github.com/alettieri
		// Check if the specified category id is valid
		if (Category_Model::is_valid_category($c))
		{
			// Filter incidents by the specified category
			$join = "\nINNER JOIN ".$this->table_prefix."incident_category AS ic ON ic.incident_id = i.id ";
			$join .= "\nINNER JOIN ".$this->table_prefix."category AS c ON c.id=ic.category_id ";

			// Overwrite the current where clause in $where
			$where = $join."\nWHERE c.id = $c AND i.incident_active = 1 AND $location_id_in";
		}
		
		$sortby = " GROUP BY i.id ORDER BY $this->order_field $this->sort";
		$limit = " LIMIT 0, $this->list_limit";
		
		return $this->_get_incidents($where.$sortby, $limit);
        
    }
Exemple #26
0
 function index()
 {
     $this->template->content = new View('admin/categories');
     $this->template->content->title = Kohana::lang('ui_admin.categories');
     // setup and initialize form field names
     $form = array('action' => '', 'category_id' => '', 'parent_id' => '', 'category_title' => '', 'category_description' => '', 'category_color' => '', 'category_image' => '');
     // copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     $parents_array = array();
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->action == 'a') {
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('parent_id', 'required', 'numeric');
             $post->add_rules('category_title', 'required', 'length[3,80]');
             $post->add_rules('category_description', 'required');
             $post->add_rules('category_color', 'required', 'length[6,6]');
             $post->add_rules('category_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]');
             $post->add_callbacks('parent_id', array($this, 'parent_id_chk'));
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             $category_id = $post->category_id;
             $category = new Category_Model($category_id);
             if ($post->action == 'd') {
                 // Delete Action
                 $category->delete($category_id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } else {
                 if ($post->action == 'v') {
                     // Show/Hide Action
                     if ($category->loaded == true) {
                         if ($category->category_visible == 1) {
                             $category->category_visible = 0;
                         } else {
                             $category->category_visible = 1;
                         }
                         $category->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                     }
                 } else {
                     if ($post->action == 'i') {
                         // Delete Image/Icon Action
                         if ($category->loaded == true) {
                             $category_image = $category->category_image;
                             if (!empty($category_image) && file_exists(Kohana::config('upload.directory', TRUE) . $category_image)) {
                                 unlink(Kohana::config('upload.directory', TRUE) . $category_image);
                             }
                             $category->category_image = null;
                             $category->save();
                             $form_saved = TRUE;
                             $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                         }
                     } else {
                         if ($post->action == 'a') {
                             // Save Action
                             $category->parent_id = $post->parent_id;
                             $category->category_title = $post->category_title;
                             $category->category_description = $post->category_description;
                             $category->category_color = $post->category_color;
                             $category->save();
                             // Upload Image/Icon
                             $filename = upload::save('category_image');
                             if ($filename) {
                                 $new_filename = "category_" . $category->id . "_" . time();
                                 // Resize Image to 32px if greater
                                 Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".png");
                                 // Remove the temporary file
                                 unlink($filename);
                                 // Delete Old Image
                                 $category_old_image = $category->category_image;
                                 if (!empty($category_old_image) && file_exists(Kohana::config('upload.directory', TRUE) . $category_old_image)) {
                                     unlink(Kohana::config('upload.directory', TRUE) . $category_old_image);
                                 }
                                 // Save
                                 $category->category_image = $new_filename . ".png";
                                 $category->save();
                             }
                             $form_saved = TRUE;
                             $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                         }
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('category'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('category')->where('parent_id', '0')->count_all()));
     $categories = ORM::factory('category')->where('parent_id', '0')->orderby('category_title', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $parents_array = ORM::factory('category')->where('parent_id', '0')->select_list('id', 'category_title');
     // add none to the list
     $parents_array[0] = "--- Top Level Category ---";
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->categories = $categories;
     $this->template->content->parents_array = $parents_array;
     // Locale (Language) Array
     $this->template->content->locale_array = Kohana::config('locale.all_languages');
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
     $this->template->js = new View('admin/categories_js');
 }
Exemple #27
0
 public function impact()
 {
     $this->template->content = new View('admin/stats/impact');
     $this->template->content->title = Kohana::lang('ui_admin.statistics');
     // Javascript Header
     $this->themes->raphael_enabled = TRUE;
     $this->themes->js = new View('admin/stats/stats_js');
     $this->template->content->failure = '';
     // Set the date range (how many days in the past from today?)
     $range = (isset($_GET['range']) and is_int($_GET['range'])) ? $_GET['range'] : 10000;
     // Get all reports so go back far into the past
     $this->template->content->range = $range;
     // Get an arbitrary date range
     $dp1 = isset($_GET['dp1']) ? $_GET['dp1'] : null;
     $dp2 = isset($_GET['dp2']) ? $_GET['dp2'] : null;
     // Report Data
     $data = Stats_Model::get_report_stats(false, true, $range, $dp1, $dp2);
     // If we failed to get hit data, fail.
     if (!isset($data['category_counts'])) {
         $this->template->content->num_reports = 0;
         $this->template->content->num_categories = 0;
         $this->template->impact_json = '';
         $this->template->content->dp1 = $dp1;
         $this->template->content->dp2 = $dp2;
         return false;
     }
     $json = array();
     $use_log = '';
     $json['buckets'] = array();
     $cat_report_count = array();
     $category_counter = array();
     foreach ($data['category_counts'] as $timestamp => $count_array) {
         $line = array();
         // If this number is greater than 0, we'll show the line
         $display_test = 0;
         foreach ($count_array as $category_id => $count) {
             $category_counter[$category_id] = 1;
             // We aren't allowing 0s
             if ($count > 0) {
                 $line[] = array($category_id, $count);
                 $display_test += $count;
                 // If we see a count over 50 (picked this arbitrarily), then switch to log format
                 if ($count > 50) {
                     $use_log = 1;
                 }
                 // Count the number of reports so we have something useful to show in the legend
                 if (!isset($cat_report_count[$category_id])) {
                     $cat_report_count[$category_id] = 0;
                 }
                 $cat_report_count[$category_id] += $count;
             }
         }
         if ($display_test > 0) {
             $json['buckets'][] = array('d' => $timestamp, 'i' => $line);
         }
     }
     $this->template->content->num_reports = $data['total_reports'];
     $this->template->content->num_categories = $data['total_categories'];
     $json['use_log'] = $use_log;
     $json['categories'] = array();
     // Grab category data
     $cats = Category_Model::categories();
     foreach ($cats as $category_id => $cat_array) {
         $report_count = 0;
         if (isset($cat_report_count[$category_id])) {
             $report_count = $cat_report_count[$category_id];
         }
         $json['categories'][$category_id] = array("name" => $cat_array['category_title'], "fill" => '#' . $cat_array['category_color'], "reports" => $report_count);
     }
     $this->themes->impact_json = json_encode($json);
     // Set the date
     $this->template->content->dp1 = date('Y-m-d', $data['earliest_report_time']);
     $this->template->content->dp2 = date('Y-m-d', $data['latest_report_time']);
 }
Exemple #28
0
 /**
  * Generates a category tree view - recursively iterates
  *
  * @return string
  */
 public static function get_category_tree_view()
 {
     // To hold the category data
     $category_data = array();
     // Database table prefix
     $table_prefix = Kohana::config('database.default.table_prefix');
     // Database instance
     $db = new Database();
     // Fetch all the top level parent categories
     foreach (Category_Model::get_categories() as $category) {
         self::_extend_category_data($category_data, $category);
     }
     // NOTES: Emmanuel Kala - Aug 5, 2011
     // Initialize the report totals for the parent categories just in case
     // the deployment does not have sub-categories in which case the query
     // below won't return a result
     self::_init_parent_category_report_totals($category_data, $table_prefix);
     // Query to fetch the report totals for the parent categories
     $sql = "SELECT c2.id,  COUNT(DISTINCT ic.incident_id)  AS report_count " . "FROM " . $table_prefix . "category c, " . $table_prefix . "category c2, " . $table_prefix . "incident_category ic " . "INNER JOIN " . $table_prefix . "incident i ON (ic.incident_id = i.id) " . "WHERE (ic.category_id = c.id OR ic.category_id = c2.id) " . "AND c.parent_id = c2.id " . "AND i.incident_active = 1 " . "AND c2.category_visible = 1 " . "AND c.category_visible = 1 " . "AND c2.parent_id = 0 " . "AND c2.category_title != \"Trusted Reports\" " . "GROUP BY c2.id " . "ORDER BY c2.id ASC";
     // Update the report_count field of each top-level category
     foreach ($db->query($sql) as $category_total) {
         // Check if the category exists
         if (array_key_exists($category_total->id, $category_data)) {
             // Update
             $category_data[$category_total->id]['report_count'] = $category_total->report_count;
         }
     }
     // Fetch the other categories
     $sql = "SELECT c.id, c.parent_id, c.category_title, c.category_color, COUNT(c.id) report_count " . "FROM " . $table_prefix . "category c " . "INNER JOIN " . $table_prefix . "incident_category ic ON (ic.category_id = c.id) " . "INNER JOIN " . $table_prefix . "incident i ON (ic.incident_id = i.id) " . "WHERE c.category_visible = 1 " . "AND i.incident_active = 1 " . "GROUP BY c.category_title " . "ORDER BY c.category_title ASC";
     // Add child categories
     foreach ($db->query($sql) as $category) {
         // Extend the category data array
         self::_extend_category_data($category_data, $category);
         if (array_key_exists($category->parent_id, $category_data)) {
             // Add children
             $category_data[$category->parent_id]['children'][$category->id] = array('category_title' => $category->category_title, 'parent_id' => $category->parent_id, 'category_color' => $category->category_color, 'report_count' => $category->report_count, 'children' => array());
         }
     }
     // Generate and return the HTML
     return self::_generate_treeview_html($category_data);
 }
Exemple #29
0
    echo $term['term_description'];
    ?>
</td>
                    <td><a href="<?php 
    echo SITE_URL . 'category.php?term_id=' . $term['term_id'];
    ?>
"><img src="<?php 
    echo SITE_URL;
    ?>
img/open-new-window.gif" /></a></td>
                    <td><a href="<?php 
    echo SITE_URL . 'admin/admin_log.php?term_id=' . $term['term_id'];
    ?>
">
                            <?php 
    echo Category_Model::getInstance()->getPostsNumByTerm($term['term_id']);
    ?>
</a></td>
                    <td>
                        <a href="" class="admin-btn-edit btn-small">编辑 </a>
                        <a href="" class="text-danger admin-btn-delete btn-small">删除</a>
                    </td>
                </tr>
            <?php 
}
?>
            </tbody>
        </table>
        <div class="table-bottom-nav">
            <span>选中项:</span><a id="delete-selected" class="text-danger btn-small" href="" >删除</a>
        </div>
Exemple #30
0
" name="<?php 
        echo 'category[]';
        ?>
"/>
 <?php 
        for ($i = 0; isset($mlist[$k]['questionnaires']) && $i < count($mlist[$k]['questionnaires']); $i++) {
            ?>
 	 
     <div style="width:100%; float:left;min-height:180px;" class="questionnaires">
   
    <?php 
            if (isset($mlist[$k]['category']) && $mlist[$k]['category'] != $category) {
                ?>
    
    <?php 
                $category_model = new Category_Model();
                $this->db->where('category.uid', $mlist[$k]['parent_id']);
                $mr_parent = $category_model->get();
                echo isset($mr_parent[0]['category']) && $parent_category != $mr_parent[0]['category'] ? '<div style="font-size:36px">' . $mr_parent[0]['category'] . ' </div>' : "";
                if (isset($mr_parent[0]['category'])) {
                    $parent_category = $mr_parent[0]['category'];
                }
                ?>
    <div><h1>
   
   
	<?php 
                echo $mlist[$k]['category'];
                $category = $mlist[$k]['category'];
                ?>
</h1></div>