[PC-BSD Commits] r1499 - in websites/pbidir.com/bibivu: bin lib slib
svn at pcbsd.org
svn at pcbsd.org
Sat Mar 1 08:27:50 PST 2008
Author: fabry
Date: 2008-03-01 08:27:50 -0800 (Sat, 01 Mar 2008)
New Revision: 1499
Modified:
websites/pbidir.com/bibivu/bin/admin.php
websites/pbidir.com/bibivu/bin/start.php
websites/pbidir.com/bibivu/lib/pbi.php
websites/pbidir.com/bibivu/lib/permissions.php
websites/pbidir.com/bibivu/lib/user.php
websites/pbidir.com/bibivu/slib/lang.php
Log:
A user can set his own language preferences and see the site with that language each time that returns to the site. fixes #97
Modified: websites/pbidir.com/bibivu/bin/admin.php
===================================================================
--- websites/pbidir.com/bibivu/bin/admin.php 2008-03-01 13:50:46 UTC (rev 1498)
+++ websites/pbidir.com/bibivu/bin/admin.php 2008-03-01 16:27:50 UTC (rev 1499)
@@ -1,356 +1,356 @@
-<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
-// ------------------------------------------------------------------------
-
-class admin extends bibivu{
- public $ajax = false;
- private $limitpp = 50; //how many per page
- /**
- * Initialize the default class
- *
- * @access private
- * @return void
- */
- public function __construct(){
- parent::__construct();
- session_start();
- $task = $this->uri->get(TASK_KEY, '');
- if($task=='update'){
- $this->load_library($task);
- return true;
- }
- $task = $this->uri->get(TASK_KEY, '');
- $this->ajax = isset($_POST['ajax']) || isset($_GET['ajax']);
- $this->load_library('table_prototype');
- $this->load_library('pbi'); //this is enough
- $this->load_library('permissions');
-
- $this->display->assign('pbi_uri',$this->uri->create_uri(array(TASK_KEY=>'pbi')));
- $this->display->assign('is_logged',$this->permissions->is_logged());
- load_library('menu')->create_menu($this->display);
-
- if($this->permissions->is_logged() && method_exists($this,'web_'.$task) && is_callable(array($this,'web_'.$task))){
- $this->display->assign('task',$task);
- $this->uri->auto_add(CLASS_KEY,'admin');
- $this->uri->auto_add(TASK_KEY,$task);
- $this->{'web_'.$task}();
- } else {
- $uri = $this->display->get('home_uri');
- $this->redirect($uri);
- }
- }
-
- public function display($page='home', $show_head_foot=true){
- $this->display->start($show_head_foot,'pbidir');
- $this->display->show('pbidir/'.$page);
- $this->display->end($show_head_foot,'pbidir');
- }
-
- /************************************************
- * MANAGE TABLES
- ************************************************/
- private function _check_can($what, $how, $owner=array(), $record=NULL){
- if(!is_null($record) && is_array($owner) && $owner!=array() && isset($owner['from_field']) && isset($record[$owner['from_field']])){
- $owner['id'] = $record[$owner['from_field']];
- return $this->permissions->can($what, $how, $owner);
- } else {
-// var_dump($this->permissions->can($what, $how),$what,$how);
- return $this->permissions->can($what, $how);
- }
- }
- private function _manage($what, $owner=array()){
- //create a list of mirrors
- $this->load_library($what);
- $this->display->assign('ajax',$this->ajax);
- $this->display->assign('fields',$this->$what->get_fields());
- $this->display->assign('owner',$owner);
- $this->display->assign('what',$what);
- $this->display->assign('related_tables',$this->$what->get_related_tables());
- $this->display->assign('save_uri',$this->uri->create_uri(array('save'=>'', 'ajax'=>'')));
- $this->display->assign('delete_uri',$this->uri->create_uri(array('delete'=>'', 'ajax'=>'')));
- $no_access = false;
- if(!is_null($this->uri->get('add',NULL)) || !is_null($this->uri->get('edit',NULL))){
- $this->uri->set('id', (int)$this->uri->get('id'));
- $filters = array();
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
- $records = $this->$what->get_all($filters, array(), array(), 1);
- if(!isset($records[0])) $records[0]=array();
- $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
- $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
- $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
- if($this->display->get('can_read')){
- $this->display->assign('record',isset($records[0])?$records[0]:array());
- if(!is_null($this->uri->get('add',NULL))){
- $get_forced = array();
- $get = $this->uri->get();
- $str = '^('.implode('|', array_keys($this->display->get('fields'))).')$';
- foreach($get as $key=>$value){
- if(ereg($str,$key)){
- $get_forced[$key] = $value;
- }
- }
- $this->display->assign('get_forced',$get_forced);
- $this->display->assign('title_form','Add '.$what);
- } elseif(!is_null($this->uri->get('edit',NULL))) {
- $this->display->assign('title_form','Edit '.$what.' '.$this->uri->get('id'));
- }
- $this->display('admin/form',false);
- } else {
- $no_access = true;
- }
- }elseif(!is_null($this->uri->get('view',NULL))){
- $this->uri->set('id', (int)$this->uri->get('id'));
- $filters = array();
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
- $records = $this->$what->get_all($filters, array(), array(), 1);
- if(!isset($records[0])) $records[0]=array();
- $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
- $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
- $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
- if($this->display->get('can_read')){
- $this->display->assign('record',isset($records[0])?$records[0]:array());
- $this->display->assign('title_form','View '.$what.' '.$this->uri->get('id'));
- $this->display('admin/view',false);
- } else {
- $no_access = true;
- }
- }elseif(!is_null($this->uri->get('save',NULL))){
- $this->uri->set('id', isset($_POST['id'])?$_POST['id']:0);
- $filters = array();
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
- $records = $this->$what->get_all($filters, array(), array(), 1);
- if(!isset($records[0])) $records[0]=array();
- $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
- $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
- $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
- if($this->display->get('can_write')){
- $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
- $this->display->start();
- $ret = false;
- $verification =& load_library('verification');
- foreach($_POST as $kk=>$vv){
- $_POST[$kk] = trim(htmlentities($vv, ENT_COMPAT, 'UTF-8'));
- //here I should check if all the values needed are there
- //and if they are in the correct format (lenght, type, etc..)
- $get_forced = array();
- $fields = $this->display->get('fields');
- // $str = '^('.implode('|', array_keys($fields)).')$';
- foreach($_POST as $key=>$value){
- if(isset($fields[$key])){
- if($value=='' && $fields[$key]['required']){
- echo $fields[$key]['text'].' required!!';
- $ret = false;
- $this->display->end();
- return;
- } elseif($value!='') {
- switch($fields[$key]['type']){
- case 'uri':
- case 'url':
- $function = 'url';
- break;
- case 'number':
- $function = 'numeric';
- break;
- case 'password':
- case 'enum':
- $function = 'alphanum';
- break;
- case 'email':
- $function = 'email';
- break;
- case 'string':
- case 'text':
- default:
- $function = 'string';
- break;
-
- }
- $ver = $verification->$function($value);
- if($ver===false){
- echo $fields[$key]['text'].' should be '.$function.'!!';
- $ret = false;
- $this->display->end();
- return;
- }
- }
- }
- }
- $ret = true;
- }
- if($ret && !isset($_POST['id']) || $_POST['id']<=0){
- //adding a new one
- $ret = $this->$what->add($_POST);
- } else {
- //editing
- $ret = $this->$what->edit($_POST['id'], $_POST);
- }
- if($ret===true || is_object($ret)){
- echo 'success';
- } else {
- echo 'Problem updating '.$what."\n\n".$ret;
- }
- $this->display->end();
- } else {
- $no_access = true;
- }
- }elseif(!is_null($this->uri->get('delete',NULL))){
- $id = trim(htmlentities($_POST['id'], ENT_COMPAT, 'UTF-8'));
- $this->uri->set('id', $id);
- $filters = array();
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
- $records = $this->$what->get_all($filters, array(), array(), 1);
- if(!isset($records[0])) $records[0]=array();
- $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
- $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
- $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
- if($this->display->get('can_delete')){
- $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
- $this->display->start();
- if($id<=0){
- echo 'What do you want to delete ??';
- } else {
- if($this->$what->remove($id)){
- echo 'success';
- } else {
- echo 'Problem deleting '.$what.' '.$id;
- }
- }
- $this->display->end();
- } else {
- $no_access = true;
- }
- }elseif(!is_null($this->uri->get('search',NULL))){
- $form_field = trim(htmlentities($_POST['ff'], ENT_COMPAT, 'UTF-8'));
- $search_field = trim(htmlentities($_POST['sf'], ENT_COMPAT, 'UTF-8'));
- $search_value = trim(htmlentities($_POST['sv'], ENT_COMPAT, 'UTF-8'));
- if($search_value!=''){
- $filters = array();
- $filters[] = array('field'=>$search_field, 'operator'=>'like', 'value'=>$search_value);
- $records = $this->$what->get_all($filters, array(), array(), 1);
- } else {
- $records = array();
- }
- $this->display->assign('records',$records);
- $this->display->assign('ff',$from_field);
- $this->display->assign('sf',$search_field);
- $this->display->assign('sv',$search_value);
- $this->display('admin/search', !$this->ajax);
- } else {
- $where = array();
- $order = array();
- $group = array();
- $limit = '';
- $array_add_uri = array('add'=>'', 'ajax'=>'');
- if((isset($_POST) && is_array($_POST) && !empty($_POST)) || $this->uri->get('order','')!=''){
- $fields = $this->$what->get_fields();
- $str = '^('.implode('|', array_keys($fields)).')( (ASC|DESC))?$';
- foreach($_POST as $key=>$value){
- if(eregi($str,$key)){
- $where[] = array('field'=>$key, 'operator'=>'=', 'value'=>$value);
- $array_add_uri[$key] = $value;
- $this->uri->auto_add($key,$value);
- }
- }
- if(eregi($str,$this->uri->get('order',''))){
- if($this->uri->get('dir','ASC')=='DESC'){
- $order[] = $this->uri->get('order','').' DESC';
- } else {
- $order[] = $this->uri->get('order','').' ASC';
- $this->uri->set('dir','ASC');
- }
- } else {
- $this->uri->set('order','');
- }
- }
- if(!$this->ajax){
- $this->uri->set('page',(int)$this->uri->get('page',0));
- $limit = ($this->limitpp*$this->uri->get('page',0)).','.$this->limitpp;
-
- $this->uri->auto_add('page',$this->uri->get('page',0));
- $this->uri->auto_add('order',$this->uri->get('order'));
- $this->uri->auto_add('dir',$this->uri->get('dir'));
- }
-
- $this->display->assign('can_read',$this->_check_can($what, 'read'));
- $this->display->assign('can_write',$this->_check_can($what, 'write'));
- $this->display->assign('can_delete',$this->_check_can($what, 'delete'));
- $this->display->assign('add_uri',$this->uri->create_uri($array_add_uri));
- $this->display->assign('records',$this->$what->get_all($where, $order, $group, $limit));
- $tot = count($this->display->get('records'));
- if(!$this->ajax){
- if($tot>=$this->limitpp || $this->uri->get('page',0)>0){
- //need to get a total count, so I can display the pagination
- $tot = $this->$what->get_count($where, $group);
- }
- } else {
- $this->limitpp = $tot;
- }
-
- $this->display->assign('total_records',$tot);
- $this->display->assign('total_per_page',$this->limitpp);
- $this->display->assign('page_name','administration - '.$what);//.' - page '.($this->uri->get('page',0)+1));
- $this->display('admin/'.$this->uri->get('how','list'), !$this->ajax);
- }
- if($no_access){
- $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
- $this->display->start();
- echo 'You cannot access this page !';
- $this->display->end();
- }
- }
- public function web_mirror(){ $this->_manage('mirror'); }
- public function web_category(){ $this->_manage('category'); }
- public function web_pcbsd_version(){ $this->_manage('pcbsd_version'); }
- public function web_permission_item(){ $this->_manage('permission_item'); }
- public function web_group(){ $this->_manage('group'); }
- public function web_permission_item_group(){ $this->_manage('permission_item_group'); }
- public function web_subscriptions(){ $this->_manage('subscriptions'); }
-
- public function web_user(){
- $owner = array('from_field'=>'id',
- 'table'=>'user',
- 'field'=>'id',
- 'field_id'=>'id',
- );
- $this->_manage('user',$owner);
- }
- public function web_pbi(){
- $owner = array('from_field'=>'id',
- 'table'=>'pbi',
- 'field'=>'user_id',
- 'field_id'=>'id',
- );
- $this->_manage('pbi',$owner);
- }
- public function web_pbi_image(){
- $owner = array('from_field'=>'pbi_id',
- 'table'=>'pbi',
- 'field'=>'user_id',
- 'field_id'=>'id',
- );
- $this->_manage('pbi_image',$owner);
- }
- public function web_pbi_status(){
- $owner = array('from_field'=>'pbi_id',
- 'table'=>'pbi',
- 'field'=>'user_id',
- 'field_id'=>'id',
- );
- $this->_manage('pbi_status',$owner);
- }
- public function web_pbi_release(){
- $owner = array('from_field'=>'pbi_id',
- 'table'=>'pbi',
- 'field'=>'user_id',
- 'field_id'=>'id',
- );
- $this->_manage('pbi_release',$owner);
- }
- public function web_pbi_release_status(){
- $owner = array('from_field'=>'pbi_id',
- 'table'=>'pbi',
- 'field'=>'user_id',
- 'field_id'=>'id',
- );
- $this->_manage('pbi_release_status',$owner);
- }
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+// ------------------------------------------------------------------------
+
+class admin extends bibivu{
+ public $ajax = false;
+ private $limitpp = 50; //how many per page
+ /**
+ * Initialize the default class
+ *
+ * @access private
+ * @return void
+ */
+ public function __construct(){
+ parent::__construct();
+ session_start();
+ $task = $this->uri->get(TASK_KEY, '');
+ if($task=='update'){
+ $this->load_library($task);
+ return true;
+ }
+ $task = $this->uri->get(TASK_KEY, '');
+ $this->ajax = isset($_POST['ajax']) || isset($_GET['ajax']);
+ $this->load_library('table_prototype');
+ $this->load_library('pbi'); //this is enough
+ $this->load_library('permissions');
+
+ $this->display->assign('pbi_uri',$this->uri->create_uri(array(TASK_KEY=>'pbi')));
+ $this->display->assign('is_logged',$this->permissions->is_logged());
+ load_library('menu')->create_menu($this->display);
+
+ if($this->permissions->is_logged() && method_exists($this,'web_'.$task) && is_callable(array($this,'web_'.$task))){
+ $this->display->assign('task',$task);
+ $this->uri->auto_add(CLASS_KEY,'admin');
+ $this->uri->auto_add(TASK_KEY,$task);
+ $this->{'web_'.$task}();
+ } else {
+ $uri = $this->display->get('home_uri');
+ $this->redirect($uri);
+ }
+ }
+
+ public function display($page='home', $show_head_foot=true){
+ $this->display->start($show_head_foot,'pbidir');
+ $this->display->show('pbidir/'.$page);
+ $this->display->end($show_head_foot,'pbidir');
+ }
+
+ /************************************************
+ * MANAGE TABLES
+ ************************************************/
+ private function _check_can($what, $how, $owner=array(), $record=NULL){
+ if(!is_null($record) && is_array($owner) && $owner!=array() && isset($owner['from_field']) && isset($record[$owner['from_field']])){
+ $owner['id'] = $record[$owner['from_field']];
+ return $this->permissions->can($what, $how, $owner);
+ } else {
+// var_dump($this->permissions->can($what, $how),$what,$how);
+ return $this->permissions->can($what, $how);
+ }
+ }
+ private function _manage($what, $owner=array()){
+ //create a list of mirrors
+ $this->load_library($what);
+ $this->display->assign('ajax',$this->ajax);
+ $this->display->assign('fields',$this->$what->get_fields());
+ $this->display->assign('owner',$owner);
+ $this->display->assign('what',$what);
+ $this->display->assign('related_tables',$this->$what->get_related_tables());
+ $this->display->assign('save_uri',$this->uri->create_uri(array('save'=>'', 'ajax'=>'')));
+ $this->display->assign('delete_uri',$this->uri->create_uri(array('delete'=>'', 'ajax'=>'')));
+ $no_access = false;
+ if(!is_null($this->uri->get('add',NULL)) || !is_null($this->uri->get('edit',NULL))){
+ $this->uri->set('id', (int)$this->uri->get('id'));
+ $filters = array();
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
+ $records = $this->$what->get_all($filters, array(), array(), 1);
+ if(!isset($records[0])) $records[0]=array();
+ $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
+ $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
+ $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
+ if($this->display->get('can_read')){
+ $this->display->assign('record',isset($records[0])?$records[0]:array());
+ if(!is_null($this->uri->get('add',NULL))){
+ $get_forced = array();
+ $get = $this->uri->get();
+ $str = '^('.implode('|', array_keys($this->display->get('fields'))).')$';
+ foreach($get as $key=>$value){
+ if(ereg($str,$key)){
+ $get_forced[$key] = $value;
+ }
+ }
+ $this->display->assign('get_forced',$get_forced);
+ $this->display->assign('title_form','Add '.$what);
+ } elseif(!is_null($this->uri->get('edit',NULL))) {
+ $this->display->assign('title_form','Edit '.$what.' '.$this->uri->get('id'));
+ }
+ $this->display('admin/form',false);
+ } else {
+ $no_access = true;
+ }
+ }elseif(!is_null($this->uri->get('view',NULL))){
+ $this->uri->set('id', (int)$this->uri->get('id'));
+ $filters = array();
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
+ $records = $this->$what->get_all($filters, array(), array(), 1);
+ if(!isset($records[0])) $records[0]=array();
+ $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
+ $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
+ $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
+ if($this->display->get('can_read')){
+ $this->display->assign('record',isset($records[0])?$records[0]:array());
+ $this->display->assign('title_form','View '.$what.' '.$this->uri->get('id'));
+ $this->display('admin/view',false);
+ } else {
+ $no_access = true;
+ }
+ }elseif(!is_null($this->uri->get('save',NULL))){
+ $this->uri->set('id', isset($_POST['id'])?$_POST['id']:0);
+ $filters = array();
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
+ $records = $this->$what->get_all($filters, array(), array(), 1);
+ if(!isset($records[0])) $records[0]=array();
+ $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
+ $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
+ $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
+ if($this->display->get('can_write')){
+ $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
+ $this->display->start();
+ $ret = false;
+ $verification =& load_library('verification');
+ foreach($_POST as $kk=>$vv){
+ $_POST[$kk] = trim(htmlentities($vv, ENT_COMPAT, 'UTF-8'));
+ //here I should check if all the values needed are there
+ //and if they are in the correct format (lenght, type, etc..)
+ $get_forced = array();
+ $fields = $this->display->get('fields');
+ // $str = '^('.implode('|', array_keys($fields)).')$';
+ foreach($_POST as $key=>$value){
+ if(isset($fields[$key])){
+ if($value=='' && $fields[$key]['required']){
+ echo $fields[$key]['text'].' required!!';
+ $ret = false;
+ $this->display->end();
+ return;
+ } elseif($value!='') {
+ switch($fields[$key]['type']){
+ case 'uri':
+ case 'url':
+ $function = 'url';
+ break;
+ case 'number':
+ $function = 'numeric';
+ break;
+ case 'password':
+ case 'enum':
+ $function = 'alphanum';
+ break;
+ case 'email':
+ $function = 'email';
+ break;
+ case 'string':
+ case 'text':
+ default:
+ $function = 'string';
+ break;
+
+ }
+ $ver = $verification->$function($value);
+ if($ver===false){
+ echo $fields[$key]['text'].' should be '.$function.'!!';
+ $ret = false;
+ $this->display->end();
+ return;
+ }
+ }
+ }
+ }
+ $ret = true;
+ }
+ if($ret && !isset($_POST['id']) || $_POST['id']<=0){
+ //adding a new one
+ $ret = $this->$what->add($_POST);
+ } else {
+ //editing
+ $ret = $this->$what->edit($_POST['id'], $_POST);
+ }
+ if($ret===true || is_object($ret)){
+ echo 'success';
+ } else {
+ echo 'Problem updating '.$what."\n\n".$ret;
+ }
+ $this->display->end();
+ } else {
+ $no_access = true;
+ }
+ }elseif(!is_null($this->uri->get('delete',NULL))){
+ $id = trim(htmlentities($_POST['id'], ENT_COMPAT, 'UTF-8'));
+ $this->uri->set('id', $id);
+ $filters = array();
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get('id'));
+ $records = $this->$what->get_all($filters, array(), array(), 1);
+ if(!isset($records[0])) $records[0]=array();
+ $this->display->assign('can_read',$this->_check_can($what, 'read', $owner, $records[0]));
+ $this->display->assign('can_write',$this->_check_can($what, 'write', $owner, $records[0]));
+ $this->display->assign('can_delete',$this->_check_can($what, 'delete', $owner, $records[0]));
+ if($this->display->get('can_delete')){
+ $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
+ $this->display->start();
+ if($id<=0){
+ echo 'What do you want to delete ??';
+ } else {
+ if($this->$what->remove($id)){
+ echo 'success';
+ } else {
+ echo 'Problem deleting '.$what.' '.$id;
+ }
+ }
+ $this->display->end();
+ } else {
+ $no_access = true;
+ }
+ }elseif(!is_null($this->uri->get('search',NULL))){
+ $form_field = trim(htmlentities($_POST['ff'], ENT_COMPAT, 'UTF-8'));
+ $search_field = trim(htmlentities($_POST['sf'], ENT_COMPAT, 'UTF-8'));
+ $search_value = trim(htmlentities($_POST['sv'], ENT_COMPAT, 'UTF-8'));
+ if($search_value!=''){
+ $filters = array();
+ $filters[] = array('field'=>$search_field, 'operator'=>'like', 'value'=>$search_value);
+ $records = $this->$what->get_all($filters, array(), array(), 1);
+ } else {
+ $records = array();
+ }
+ $this->display->assign('records',$records);
+ $this->display->assign('ff',$from_field);
+ $this->display->assign('sf',$search_field);
+ $this->display->assign('sv',$search_value);
+ $this->display('admin/search', !$this->ajax);
+ } else {
+ $where = array();
+ $order = array();
+ $group = array();
+ $limit = '';
+ $array_add_uri = array('add'=>'', 'ajax'=>'');
+ if((isset($_POST) && is_array($_POST) && !empty($_POST)) || $this->uri->get('order','')!=''){
+ $fields = $this->$what->get_fields();
+ $str = '^('.implode('|', array_keys($fields)).')( (ASC|DESC))?$';
+ foreach($_POST as $key=>$value){
+ if(eregi($str,$key)){
+ $where[] = array('field'=>$key, 'operator'=>'=', 'value'=>$value);
+ $array_add_uri[$key] = $value;
+ $this->uri->auto_add($key,$value);
+ }
+ }
+ if(eregi($str,$this->uri->get('order',''))){
+ if($this->uri->get('dir','ASC')=='DESC'){
+ $order[] = $this->uri->get('order','').' DESC';
+ } else {
+ $order[] = $this->uri->get('order','').' ASC';
+ $this->uri->set('dir','ASC');
+ }
+ } else {
+ $this->uri->set('order','');
+ }
+ }
+ if(!$this->ajax){
+ $this->uri->set('page',(int)$this->uri->get('page',0));
+ $limit = ($this->limitpp*$this->uri->get('page',0)).','.$this->limitpp;
+
+ $this->uri->auto_add('page',$this->uri->get('page',0));
+ $this->uri->auto_add('order',$this->uri->get('order'));
+ $this->uri->auto_add('dir',$this->uri->get('dir'));
+ }
+
+ $this->display->assign('can_read',$this->_check_can($what, 'read'));
+ $this->display->assign('can_write',$this->_check_can($what, 'write'));
+ $this->display->assign('can_delete',$this->_check_can($what, 'delete'));
+ $this->display->assign('add_uri',$this->uri->create_uri($array_add_uri));
+ $this->display->assign('records',$this->$what->get_all($where, $order, $group, $limit));
+ $tot = count($this->display->get('records'));
+ if(!$this->ajax){
+ if($tot>=$this->limitpp || $this->uri->get('page',0)>0){
+ //need to get a total count, so I can display the pagination
+ $tot = $this->$what->get_count($where, $group);
+ }
+ } else {
+ $this->limitpp = $tot;
+ }
+
+ $this->display->assign('total_records',$tot);
+ $this->display->assign('total_per_page',$this->limitpp);
+ $this->display->assign('page_name','administration - '.$what);//.' - page '.($this->uri->get('page',0)+1));
+ $this->display('admin/'.$this->uri->get('how','list'), !$this->ajax);
+ }
+ if($no_access){
+ $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
+ $this->display->start();
+ echo 'You cannot access this page !';
+ $this->display->end();
+ }
+ }
+ public function web_mirror(){ $this->_manage('mirror'); }
+ public function web_category(){ $this->_manage('category'); }
+ public function web_pcbsd_version(){ $this->_manage('pcbsd_version'); }
+ public function web_permission_item(){ $this->_manage('permission_item'); }
+ public function web_group(){ $this->_manage('group'); }
+ public function web_permission_item_group(){ $this->_manage('permission_item_group'); }
+ public function web_subscriptions(){ $this->_manage('subscriptions'); }
+
+ public function web_user(){
+ $owner = array('from_field'=>'id',
+ 'table'=>'user',
+ 'field'=>'id',
+ 'field_id'=>'id',
+ );
+ $this->_manage('user',$owner);
+ }
+ public function web_pbi(){
+ $owner = array('from_field'=>'id',
+ 'table'=>'pbi',
+ 'field'=>'user_id',
+ 'field_id'=>'id',
+ );
+ $this->_manage('pbi',$owner);
+ }
+ public function web_pbi_image(){
+ $owner = array('from_field'=>'pbi_id',
+ 'table'=>'pbi',
+ 'field'=>'user_id',
+ 'field_id'=>'id',
+ );
+ $this->_manage('pbi_image',$owner);
+ }
+ public function web_pbi_status(){
+ $owner = array('from_field'=>'pbi_id',
+ 'table'=>'pbi',
+ 'field'=>'user_id',
+ 'field_id'=>'id',
+ );
+ $this->_manage('pbi_status',$owner);
+ }
+ public function web_pbi_release(){
+ $owner = array('from_field'=>'pbi_id',
+ 'table'=>'pbi',
+ 'field'=>'user_id',
+ 'field_id'=>'id',
+ );
+ $this->_manage('pbi_release',$owner);
+ }
+ public function web_pbi_release_status(){
+ $owner = array('from_field'=>'pbi_id',
+ 'table'=>'pbi',
+ 'field'=>'user_id',
+ 'field_id'=>'id',
+ );
+ $this->_manage('pbi_release_status',$owner);
+ }
}
\ No newline at end of file
Modified: websites/pbidir.com/bibivu/bin/start.php
===================================================================
--- websites/pbidir.com/bibivu/bin/start.php 2008-03-01 13:50:46 UTC (rev 1498)
+++ websites/pbidir.com/bibivu/bin/start.php 2008-03-01 16:27:50 UTC (rev 1499)
@@ -1,581 +1,583 @@
-<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
-// ------------------------------------------------------------------------
-
-class start extends bibivu{
- public $ajax = false;
- /**
- * Initialize the default class
- *
- * @access private
- * @return void
- */
- public function __construct(){
- parent::__construct();
- session_start();
- $task = $this->uri->get(TASK_KEY, '');
- switch($task){
- case 'update':
- $this->load_library($task);
- return true;
- break;
- case 'mirrors':
- $mirrors = load_library('mirror');
- $tmps = $mirrors->get_all();
- if(isset($_GET['update'])){
- echo '<pre>'."\n";
- foreach($tmps as $key=>$value){
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$value['id']);
- echo $value['id'].': '.$value['name'].' - '.$value['url'].' => '.$mirrors->get_record($filters)->update_mirror('PBI/.zupdate')."\n";
- flush();
- }
- echo '</pre>'."\n";
- return true;
- }
- break;
- }
-
- $this->ajax = isset($_POST['ajax']) || isset($_GET['ajax']);
- $this->load_library('table_prototype');
- $this->load_library('pbi'); //this is enough
- $this->load_library('permissions');
-
- $this->display->assign('is_logged',$this->permissions->is_logged());
- $this->display->assign('pbi_uri',$this->uri->create_uri(array(TASK_KEY=>'pbi')));
- load_library('menu')->create_menu($this->display);
-
- if(method_exists($this,'web_'.$task) && is_callable(array($this,'web_'.$task))){
- $this->display->assign('task',$task);
- $this->{'web_'.$task}();
- } else {
- if($this->uri->get_num(1)==''){
- $this->display->assign('task','home');
- $this->web_home();
- } else {
- $this->display->assign('search_text',trim(str_replace('/',' ', at implode(' ', $this->uri->get_GETnum()))));
- $this->display->assign('task','search');
- $this->web_search();
- }
- }
- }
-
- public function display($page='home', $show_head_foot=true){
- $this->display->start($show_head_foot,'pbidir');
- $this->display->show('pbidir/'.$page);
- $this->display->end($show_head_foot,'pbidir');
- }
-
- public function web_home(){
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'show_on_site', 'operator'=>'=', 'value'=>'y');
- $group = array();
- $order = array('name');
- $limit = '';
- $this->display->assign('categories', $this->table_prototype->get_raw($filters, $order, $group, $limit,'category'));
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $group = array('pbi_id');
- $order = array('date_last_status_id DESC');
- $limit = 20;
- $join = array();
- $fields = array('max(date_last_status_id) date_last_status_id', 'MAX(id) id');
- $this->display->assign('latest_releases', load_library('pbi_release')->get_all($filters, $order, $group, $limit, '', $join, $fields));
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $group = array();
- $order = array('date_added DESC');
- $limit = 20;
- $this->display->assign('latest', $this->pbi->get_raw($filters, $order, $group, $limit));
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $group = array();
- $order = array('total_download DESC');
- $limit = 20;
- $this->display->assign('most_download', $this->pbi->get_raw($filters, $order, $group, $limit));
-
- $this->display->assign('title', 'Your PC-BSD software');
- $this->display('home');
- }
-
- public function web_contact_us(){
- $this->display->assign('title', 'Contact Us');
- $this->display('contact_us');
- }
-
- public function web_category(){
- $filters = array();
- $filters[] = array('field'=>'web_alias', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
- $category = $this->table_prototype->get_record($filters,'category')->get_info();
- if(!isset($category['id']) || $category['web_alias']!=$this->uri->get_num(3)){
- //package doesn't exists
- $this->display->assign('message', 'Category not found!');
- $this->display('message');
- return;
- }
-
- $pbis_per_page = 20;
- $order = $this->uri->get_num(4, 'name');
- $order_mode = $this->uri->get_num(5, 'asc');
- $current_page = $this->uri->get_num(6,0);
-
- switch(strtolower($order)){
- case 'added':
- $order_field = 'date_added';
- break;
- case 'rating':
- $order_field = '(total_points+5)/(total_votes+1)';
- break;
- case 'download':
- $order_field = 'total_download';
- break;
- case 'name':
- default:
- $order='name';
- $order_field = 'name';
- }
- $order_mode = $order_mode=='desc'?'desc':'asc';
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'category_id', 'operator'=>'=', 'value'=>$category['id']);
- list($category['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
-
- $this->display->assign('result', $category);
- $this->display->assign('breadcrumb_text', $category['name']);
- $pbis = $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'), array(), ($current_page*$pbis_per_page).','.$pbis_per_page);
- $this->display->assign('pbis', $pbis);
-
- $this->display->assign('order', $order);
- $this->display->assign('order_mode', $order_mode);
- $this->display->assign('pbis_per_page', $pbis_per_page);
- $this->display->assign('current_page', $current_page);
-
- $this->display->assign('title', $category['name']);
- $this->display('search');
- }
-
- public function web_pbi(){
- if(!is_numeric($this->uri->get_num(3))){
- $this->redirect($this->display->get('home_uri'), 'Error opening this page', 3, true, 'pbidir');
- return;
- }
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
- $pbi = $this->pbi->get_record($filters)->get_info();
- if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
- //package doesn't exists
- $this->display->assign('message', 'Package '.$this->uri->get_num(3).' not found!');
- $this->display('message');
- return;
- }
- if($this->uri->get_num(4)=='vote' && $this->uri->get_num(5)>0 && $this->permissions->can('pbi_vote')){
- //voting the pbi
- //return a normal TEXT message
- $vote = $this->uri->get_num(5);
- if($this->ajax){
- $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
- $this->display->start();
- } else {
- $uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
- }
- if($this->pbi->vote_pbi($pbi['id'],$vote)){
- if($this->ajax){
- $ret = $this->pbi->get_vote($pbi['id']);
- if(is_numeric($ret)){
- echo number_format($ret, 2, '.', '');
- } else {
- echo 0;
- }
- } else {
- $this->redirect($uri, 'Vote Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
- }
- } else {
- if($this->ajax){
- echo 'problems saving your vote!';
- } else {
- $this->redirect($uri, 'Problems saving your vote! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
- }
- }
- if($this->ajax){
- $this->display->end();
- }
- return;
- } else {
- $filters = array();
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['category_id']);
- $category = load_library('category')->get_record($filters)->get_info();
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
- $limit = ''; //was 3
- $this->display->assign('pbi_releases', load_library('pbi_release')->get_all($filters, array('date_added DESC'), array(), $limit));
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
- $this->display->assign('pbi_images', load_library('pbi_image')->get_all($filters, array('`order`')));
-
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
- $comments = $this->table_prototype->get_all($filters, array('date_added DESC'), array(), 20,'pbi_comment');
- if(is_array($comments)){
- foreach($comments as $key=>$value){
- $comments[$key]['date'] = load_library('format')->datetime($value['date_added']);
- $comments[$key]['profile_uri'] = '';
- }
- } else {
- $comments = array();
- }
-
- $this->display->assign('comment_form_uri',$this->uri->create_uri(array(TASK_KEY=>'show_comment_form')).'/'.$pbi['id']);
-
- //subscription
- if($this->display->get('is_logged')){
- $filters = array();
- $filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
- $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
- $limit = '1';
- $this->display->assign('is_subscribed', (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array()));
-
- $this->display->assign('subscribe_uri',$this->uri->create_uri(array(TASK_KEY=>'subscribe')).'/'.$pbi['id']);
- }
-
- $this->display->assign('prev_vote',isset($_SESSION['votes'][$pbi['id']])?$_SESSION['votes'][$pbi['id']]:'');
-
- $this->display->assign('can_vote',$this->permissions->can('pbi_vote', 'write'));
- $this->display->assign('can_comment',$this->permissions->can('pbi_comment', 'write'));
- if($this->permissions->can('pbi_comment', 'delete')){
- $this->display->assign('can_comment_delete',true);
- $this->display->assign('delete_comment_uri',$this->uri->create_uri(array(TASK_KEY=>'admin')).'/delete_comment/'.$pbi['id']);
- } else {
- $this->display->assign('can_comment_delete',false);
- }
-
- $owner = array('id'=>$pbi['id'],
- 'table'=>'pbi',
- 'field'=>'user_id',
- 'field_id'=>'id',
- );
- $this->display->assign('can_write',$this->permissions->can('pbi', 'write',$owner));
-
- $this->display->assign('pbi', $pbi);
- $this->display->assign('category', $category);
- $this->display->assign('comments', $comments);
-
- $this->display->assign('title', $pbi['name']);
- $this->display('pbi');
- }
- }
-
- public function web_subscribe(){
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
- $pbi = $this->pbi->get_record($filters)->get_info();
- if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
- $msg = 'PBI '.$this->uri->get_num(3).' not found !!';
- } else {
- $filters = array();
- $filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
- $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
- $limit = '1';
- $is_subscribed = (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array());
- if($is_subscribed){
- $ret = load_library('subscriptions')->delete()->where($filters)->do_db();
- } else {
- $ret = load_library('subscriptions')->insert()->set('pbi_id',$pbi['id'])->set('user_id',$this->permissions->get('id',''))->do_db();
- }
- if($ret){
- $msg = load_library('lang')->get($is_subscribed?'pbi_succesfully_unsubscribed':'pbi_succesfully_subscribed');
- } else {
- $msg = 'Problems while saving subscription! Please try again later.';
- }
- }
-
- $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
- $this->display->start();
- echo $msg;
- $this->display->end();
- }
-
- public function web_download(){
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
- $pbi = $this->pbi->get_record($filters)->get_info();
- if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
- //package doesn't exists
- $this->display->assign('message', 'Package not found!');
- $this->display('message');
- return;
- }
-
- $this->load_library('pbi_release');
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(4));
- $pbi_release = $this->pbi_release->get_record($filters)->get_info();
- if(!isset($pbi_release['id']) || $pbi_release['id']!=$this->uri->get_num(4) || $pbi_release['pbi_id']!=$this->uri->get_num(3)){
- //package doesn't exists
- $this->display->assign('message', 'Package Release not found!');
- $this->display('message');
- return;
- }
- $this->display->assign('pbi', $pbi);
- $this->display->assign('pbi_release', $pbi_release);
- if($this->uri->get_num(5)>0){
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(5));
- $mirror = $this->table_prototype->get_record($filters, 'mirror')->get_info();
- if(!isset($mirror['id']) || $mirror['id']!=$this->uri->get_num(5)){
- //package doesn't exists
- $this->display->assign('message', 'Mirror not found!');
- $this->display('message');
- return;
- }
- $this->table_prototype->insert()->from('download')->set('pbi_id',$pbi['id'])->set('download_type_id','1')->set('mirror_id',$mirror['id'])->do_db();
-
- $filters = array();
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['id']);
- $this->pbi->update()->set('total_download','total_download+1',true)->where()->do_db();
-
- $this->display->assign('mirror', $mirror);
-
- $this->display->assign('title', 'Downloading '.$pbi['name']);
- $this->display('download');
- } else {
- //have to choose the mirror to use
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'last_update', 'operator'=>'>', 'value'=>$pbi['date_last_status_id']);
- $mirror = $this->table_prototype->get_all($filters, array('name ASC','last_update DESC'), array(), '','mirror');
- $this->display->assign('mirror', $mirror);
- $this->display->assign('title', 'Downloading '.$pbi['name'].' - Choose a mirror');
- $this->display('choose_mirror');
- }
- }
-
- /*
- * This function will search the pbi database for a determinated value,
- * and will show the page with the results
- */
- public function web_search(){
- $text = trim($this->display->get('search_text'));
- $pbis_per_page = 20;
- $order = $this->uri->get_num(5);
- $order_mode = $this->uri->get_num(6);
- $current_page = $this->uri->get_num(7,0);
- switch(strtolower($order)){
- case 'added':
- $order_field = 'date_added';
- break;
- case 'rating':
- $order_field = '(total_points+5)/(total_votes+1)';
- break;
- case 'download':
- $order_field = 'total_download';
- break;
- case 'name':
- default:
- $order = 'name';
- $order_field = 'name';
- }
- $order_mode = $order_mode=='desc'?'desc':'asc';
- $order_mode = $order_mode=='desc'?'desc':'asc';
-
- if($text==''){
- $result['total_pbis'] = 0;
- $this->display->assign('pbis', array());
- } else {
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'name', 'operator'=>'LIKE', 'value'=>'%'.$text.'%');
- list($result['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
- $this->display->assign('pbis', $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'), array(), ($current_page*$pbis_per_page).','.$pbis_per_page));
- }
-
- $this->display->assign('result', $result);
- $this->display->assign('order', $order);
- $this->display->assign('order_mode', $order_mode);
- $this->display->assign('pbis_per_page', $pbis_per_page);
- $this->display->assign('current_page', $current_page);
- $this->display->assign('breadcrumb_text', htmlentities($text));
-
- $this->display->assign('pbi', load_library('lang')->get('search_page_title'));
- $this->display->assign('title', load_library('lang')->get('search_page_title'));
- $this->display('search');
-
- }
-
- /************************************************
- * ADMINISTRATION PART
- ************************************************/
- private function _get_redirect_messages($key='', $uri=''){
- if($key=='') return '';
- $messages['home'] = sprintf(load_library('lang')->get('redirect_home'),$this->display->get('home_uri'));
- $messages['previous'] = sprintf(load_library('lang')->get('redirect_home'),$uri);
-
- if(!isset($messages[$key])) return '';
- else return $messages[$key];
- }
-
- public function web_admin(){
- if(!$this->display->get('is_logged')){
- $this->display->assign('task','login');
- $this->web_admin_login();
- } else {
- $task = $this->uri->get_num(3);
- if(method_exists($this,'web_admin_'.$task) && is_callable(array($this,'web_admin_'.$task))){
- $this->display->assign('task',$task);
- $this->{'web_admin_'.$task}();
- } else {
- $this->display->assign('task','home');
- $this->web_home();
- }
- }
- }
-
- public function web_admin_login(){
- $this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
- $this->display->assign('title', load_library('lang')->get('login_page_title'));
- $user = '';
- if(!$this->cookie_check()){
- $this->display->assign('error',load_library('lang')->get('login_error_cookies'));
- }elseif(isset($_POST['username']) && isset($_POST['pws'])){
- $user = $_POST['username'];
- $ret = $this->permissions->login($user, $_POST['pws']);
- if($ret===false){
- $this->display->assign('error',load_library('lang')->get('login_failed'));
- } else {
- $this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
- return true;
- }
- }
- $this->display->assign('username',$user);
- $this->display('login');
- }
-
- public function web_register(){
- $this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
- $user = '';
- $email = '';
- if(isset($_POST['username']) && isset($_POST['email'])){
- $verification =& load_library('verification');
- $user = $_POST['username'];
- $email = $_POST['email'];
- $vemail = $_POST['vemail'];
- $error = array();
- if($email!=$vemail){
- $this->display->assign('error',load_library('lang')->get('registration_error_email_verification'));
- } elseif(!$verification->email($email)){
- $this->display->assign('error',load_library('lang')->get('registration_error_email_not_valid'));
- } elseif(!$verification->alphanum($user)){
- $this->display->assign('error',load_library('lang')->get('registration_error_user_alphanum'));
- } elseif($this->permissions->user_exists($user)){
- $this->display->assign('error',load_library('lang')->get('registration_error_user_exists'));
- } else {
- $ret = $this->permissions->register($user, $email);
- if($ret===false){
- $this->display->assign('error',load_library('lang')->get('registration_error_generic'));
- } else {
- $this->redirect($this->display->get('home_uri'), load_library('lang')->get('registration_success').' '.$this->_get_redirect_messages('home'), 10, true, 'pbidir');
- return true;
- }
- }
- }
- $this->display->assign('title', load_library('lang')->get('registration_page_title'));
- $this->display->assign('username',$user);
- $this->display->assign('email',$email);
- $this->display('registration');
- }
-
- public function web_admin_logout(){
- $this->permissions->logout();
- $this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_logout_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
- }
- /************************************************
- * COMMENTS
- ************************************************/
- public function web_show_comment_form(){
- $this->display->assign('comment_to_uri',$this->uri->create_uri(array(TASK_KEY=>'save_comment')).'/'.$this->uri->get_num(3));
- $this->display('comment/form',false);
- }
-
- public function web_admin_delete_comment(){
- $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
- $this->display->start();
- if($this->pbi->delete_comment($this->uri->get_num(4),$this->uri->get_num(5))){
- echo 'success';
- } else {
- echo 'Problems Deleting comment #'.$this->uri->get_num(5).' from pbi #'.$this->uri->get_num(4);
- }
- $this->display->end();
- }
-
- public function web_save_comment(){
- //save the comment
- $comment = trim($_POST['pbi_comment']);
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
- $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
- $pbi = $this->pbi->get_record($filters)->get_info();
- if($this->ajax){
- $this->config->set('display_headers',array('Content-Type'=> 'text/xml')); //text/xml = xml file
- } else {
- $uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
- }
- if($this->permissions->can('pbi_comment')){
- if($comment!='' && $this->pbi->add_comment($pbi['id'], htmlentities($comment, ENT_COMPAT, 'UTF-8'), $this->permissions->get('id',''),$this->permissions->get('user',''), $this->permissions->IP())!==false){
- if($this->ajax){
- $xml = array('message'=>array(
- 'error' => '',
- 'cid' => $this->pbi->db->insert_id(),
- 'user' => $this->permissions->get('user',''),
- 'body' => htmlentities($comment, ENT_COMPAT, 'UTF-8'),
- 'date' => load_library('format')->datetime(),
- )
- );
- } else {
- $this->redirect($uri, 'Comment Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
- }
- } else {
- if($this->ajax){
- $xml = array('message'=>array('error' => 'Problems saving your comment! Try Again later!'));
- } else {
- $this->redirect($uri, 'Problems saving your comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
- }
- }
- } else {
- if($this->ajax){
- $xml = array('message'=>array('error' => 'You do not have permissions to send a comment !!'));
- } else {
- $this->redirect($uri, 'You do not have permissions to send a comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
- }
- }
- if($this->ajax){
- $this->display->assign('xml',$xml);
- $this->display('xml',false);
- }
- }
-}
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+// ------------------------------------------------------------------------
+
+class start extends bibivu{
+ public $ajax = false;
+ /**
+ * Initialize the default class
+ *
+ * @access private
+ * @return void
+ */
+ public function __construct(){
+ parent::__construct();
+ session_start();
+ $task = $this->uri->get(TASK_KEY, '');
+ switch($task){
+ case 'update':
+ $this->load_library($task);
+ return true;
+ break;
+ case 'mirrors':
+ $mirrors = load_library('mirror');
+ $tmps = $mirrors->get_all();
+ if(isset($_GET['update'])){
+ echo '<pre>'."\n";
+ foreach($tmps as $key=>$value){
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$value['id']);
+ echo $value['id'].': '.$value['name'].' - '.$value['url'].' => '.$mirrors->get_record($filters)->update_mirror('PBI/.zupdate')."\n";
+ flush();
+ }
+ echo '</pre>'."\n";
+ return true;
+ }
+ break;
+ }
+
+ $this->ajax = isset($_POST['ajax']) || isset($_GET['ajax']);
+ $this->load_library('table_prototype');
+ $this->load_library('pbi'); //this is enough
+ $this->load_library('permissions');
+
+ load_library('lang')->set_lang($this->permissions->get('lang',''));
+
+ $this->display->assign('is_logged',$this->permissions->is_logged());
+ $this->display->assign('pbi_uri',$this->uri->create_uri(array(TASK_KEY=>'pbi')));
+ load_library('menu')->create_menu($this->display);
+
+ if(method_exists($this,'web_'.$task) && is_callable(array($this,'web_'.$task))){
+ $this->display->assign('task',$task);
+ $this->{'web_'.$task}();
+ } else {
+ if($this->uri->get_num(1)==''){
+ $this->display->assign('task','home');
+ $this->web_home();
+ } else {
+ $this->display->assign('search_text',trim(str_replace('/',' ', at implode(' ', $this->uri->get_GETnum()))));
+ $this->display->assign('task','search');
+ $this->web_search();
+ }
+ }
+ }
+
+ public function display($page='home', $show_head_foot=true){
+ $this->display->start($show_head_foot,'pbidir');
+ $this->display->show('pbidir/'.$page);
+ $this->display->end($show_head_foot,'pbidir');
+ }
+
+ public function web_home(){
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'show_on_site', 'operator'=>'=', 'value'=>'y');
+ $group = array();
+ $order = array('name');
+ $limit = '';
+ $this->display->assign('categories', $this->table_prototype->get_raw($filters, $order, $group, $limit,'category'));
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $group = array('pbi_id');
+ $order = array('date_last_status_id DESC');
+ $limit = 20;
+ $join = array();
+ $fields = array('max(date_last_status_id) date_last_status_id', 'MAX(id) id');
+ $this->display->assign('latest_releases', load_library('pbi_release')->get_all($filters, $order, $group, $limit, '', $join, $fields));
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $group = array();
+ $order = array('date_added DESC');
+ $limit = 20;
+ $this->display->assign('latest', $this->pbi->get_raw($filters, $order, $group, $limit));
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $group = array();
+ $order = array('total_download DESC');
+ $limit = 20;
+ $this->display->assign('most_download', $this->pbi->get_raw($filters, $order, $group, $limit));
+
+ $this->display->assign('title', 'Your PC-BSD software');
+ $this->display('home');
+ }
+
+ public function web_contact_us(){
+ $this->display->assign('title', 'Contact Us');
+ $this->display('contact_us');
+ }
+
+ public function web_category(){
+ $filters = array();
+ $filters[] = array('field'=>'web_alias', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+ $category = $this->table_prototype->get_record($filters,'category')->get_info();
+ if(!isset($category['id']) || $category['web_alias']!=$this->uri->get_num(3)){
+ //package doesn't exists
+ $this->display->assign('message', 'Category not found!');
+ $this->display('message');
+ return;
+ }
+
+ $pbis_per_page = 20;
+ $order = $this->uri->get_num(4, 'name');
+ $order_mode = $this->uri->get_num(5, 'asc');
+ $current_page = $this->uri->get_num(6,0);
+
+ switch(strtolower($order)){
+ case 'added':
+ $order_field = 'date_added';
+ break;
+ case 'rating':
+ $order_field = '(total_points+5)/(total_votes+1)';
+ break;
+ case 'download':
+ $order_field = 'total_download';
+ break;
+ case 'name':
+ default:
+ $order='name';
+ $order_field = 'name';
+ }
+ $order_mode = $order_mode=='desc'?'desc':'asc';
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'category_id', 'operator'=>'=', 'value'=>$category['id']);
+ list($category['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
+
+ $this->display->assign('result', $category);
+ $this->display->assign('breadcrumb_text', $category['name']);
+ $pbis = $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'), array(), ($current_page*$pbis_per_page).','.$pbis_per_page);
+ $this->display->assign('pbis', $pbis);
+
+ $this->display->assign('order', $order);
+ $this->display->assign('order_mode', $order_mode);
+ $this->display->assign('pbis_per_page', $pbis_per_page);
+ $this->display->assign('current_page', $current_page);
+
+ $this->display->assign('title', $category['name']);
+ $this->display('search');
+ }
+
+ public function web_pbi(){
+ if(!is_numeric($this->uri->get_num(3))){
+ $this->redirect($this->display->get('home_uri'), 'Error opening this page', 3, true, 'pbidir');
+ return;
+ }
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+ $pbi = $this->pbi->get_record($filters)->get_info();
+ if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
+ //package doesn't exists
+ $this->display->assign('message', 'Package '.$this->uri->get_num(3).' not found!');
+ $this->display('message');
+ return;
+ }
+ if($this->uri->get_num(4)=='vote' && $this->uri->get_num(5)>0 && $this->permissions->can('pbi_vote')){
+ //voting the pbi
+ //return a normal TEXT message
+ $vote = $this->uri->get_num(5);
+ if($this->ajax){
+ $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
+ $this->display->start();
+ } else {
+ $uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
+ }
+ if($this->pbi->vote_pbi($pbi['id'],$vote)){
+ if($this->ajax){
+ $ret = $this->pbi->get_vote($pbi['id']);
+ if(is_numeric($ret)){
+ echo number_format($ret, 2, '.', '');
+ } else {
+ echo 0;
+ }
+ } else {
+ $this->redirect($uri, 'Vote Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+ }
+ } else {
+ if($this->ajax){
+ echo 'problems saving your vote!';
+ } else {
+ $this->redirect($uri, 'Problems saving your vote! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+ }
+ }
+ if($this->ajax){
+ $this->display->end();
+ }
+ return;
+ } else {
+ $filters = array();
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['category_id']);
+ $category = load_library('category')->get_record($filters)->get_info();
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+ $limit = ''; //was 3
+ $this->display->assign('pbi_releases', load_library('pbi_release')->get_all($filters, array('date_added DESC'), array(), $limit));
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+ $this->display->assign('pbi_images', load_library('pbi_image')->get_all($filters, array('`order`')));
+
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+ $comments = $this->table_prototype->get_all($filters, array('date_added DESC'), array(), 20,'pbi_comment');
+ if(is_array($comments)){
+ foreach($comments as $key=>$value){
+ $comments[$key]['date'] = load_library('format')->datetime($value['date_added']);
+ $comments[$key]['profile_uri'] = '';
+ }
+ } else {
+ $comments = array();
+ }
+
+ $this->display->assign('comment_form_uri',$this->uri->create_uri(array(TASK_KEY=>'show_comment_form')).'/'.$pbi['id']);
+
+ //subscription
+ if($this->display->get('is_logged')){
+ $filters = array();
+ $filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
+ $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+ $limit = '1';
+ $this->display->assign('is_subscribed', (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array()));
+
+ $this->display->assign('subscribe_uri',$this->uri->create_uri(array(TASK_KEY=>'subscribe')).'/'.$pbi['id']);
+ }
+
+ $this->display->assign('prev_vote',isset($_SESSION['votes'][$pbi['id']])?$_SESSION['votes'][$pbi['id']]:'');
+
+ $this->display->assign('can_vote',$this->permissions->can('pbi_vote', 'write'));
+ $this->display->assign('can_comment',$this->permissions->can('pbi_comment', 'write'));
+ if($this->permissions->can('pbi_comment', 'delete')){
+ $this->display->assign('can_comment_delete',true);
+ $this->display->assign('delete_comment_uri',$this->uri->create_uri(array(TASK_KEY=>'admin')).'/delete_comment/'.$pbi['id']);
+ } else {
+ $this->display->assign('can_comment_delete',false);
+ }
+
+ $owner = array('id'=>$pbi['id'],
+ 'table'=>'pbi',
+ 'field'=>'user_id',
+ 'field_id'=>'id',
+ );
+ $this->display->assign('can_write',$this->permissions->can('pbi', 'write',$owner));
+
+ $this->display->assign('pbi', $pbi);
+ $this->display->assign('category', $category);
+ $this->display->assign('comments', $comments);
+
+ $this->display->assign('title', $pbi['name']);
+ $this->display('pbi');
+ }
+ }
+
+ public function web_subscribe(){
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+ $pbi = $this->pbi->get_record($filters)->get_info();
+ if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
+ $msg = 'PBI '.$this->uri->get_num(3).' not found !!';
+ } else {
+ $filters = array();
+ $filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
+ $filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+ $limit = '1';
+ $is_subscribed = (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array());
+ if($is_subscribed){
+ $ret = load_library('subscriptions')->delete()->where($filters)->do_db();
+ } else {
+ $ret = load_library('subscriptions')->insert()->set('pbi_id',$pbi['id'])->set('user_id',$this->permissions->get('id',''))->do_db();
+ }
+ if($ret){
+ $msg = load_library('lang')->get($is_subscribed?'pbi_succesfully_unsubscribed':'pbi_succesfully_subscribed');
+ } else {
+ $msg = 'Problems while saving subscription! Please try again later.';
+ }
+ }
+
+ $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
+ $this->display->start();
+ echo $msg;
+ $this->display->end();
+ }
+
+ public function web_download(){
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+ $pbi = $this->pbi->get_record($filters)->get_info();
+ if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
+ //package doesn't exists
+ $this->display->assign('message', 'Package not found!');
+ $this->display('message');
+ return;
+ }
+
+ $this->load_library('pbi_release');
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(4));
+ $pbi_release = $this->pbi_release->get_record($filters)->get_info();
+ if(!isset($pbi_release['id']) || $pbi_release['id']!=$this->uri->get_num(4) || $pbi_release['pbi_id']!=$this->uri->get_num(3)){
+ //package doesn't exists
+ $this->display->assign('message', 'Package Release not found!');
+ $this->display('message');
+ return;
+ }
+ $this->display->assign('pbi', $pbi);
+ $this->display->assign('pbi_release', $pbi_release);
+ if($this->uri->get_num(5)>0){
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(5));
+ $mirror = $this->table_prototype->get_record($filters, 'mirror')->get_info();
+ if(!isset($mirror['id']) || $mirror['id']!=$this->uri->get_num(5)){
+ //package doesn't exists
+ $this->display->assign('message', 'Mirror not found!');
+ $this->display('message');
+ return;
+ }
+ $this->table_prototype->insert()->from('download')->set('pbi_id',$pbi['id'])->set('download_type_id','1')->set('mirror_id',$mirror['id'])->do_db();
+
+ $filters = array();
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['id']);
+ $this->pbi->update()->set('total_download','total_download+1',true)->where()->do_db();
+
+ $this->display->assign('mirror', $mirror);
+
+ $this->display->assign('title', 'Downloading '.$pbi['name']);
+ $this->display('download');
+ } else {
+ //have to choose the mirror to use
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'last_update', 'operator'=>'>', 'value'=>$pbi['date_last_status_id']);
+ $mirror = $this->table_prototype->get_all($filters, array('name ASC','last_update DESC'), array(), '','mirror');
+ $this->display->assign('mirror', $mirror);
+ $this->display->assign('title', 'Downloading '.$pbi['name'].' - Choose a mirror');
+ $this->display('choose_mirror');
+ }
+ }
+
+ /*
+ * This function will search the pbi database for a determinated value,
+ * and will show the page with the results
+ */
+ public function web_search(){
+ $text = trim($this->display->get('search_text'));
+ $pbis_per_page = 20;
+ $order = $this->uri->get_num(5);
+ $order_mode = $this->uri->get_num(6);
+ $current_page = $this->uri->get_num(7,0);
+ switch(strtolower($order)){
+ case 'added':
+ $order_field = 'date_added';
+ break;
+ case 'rating':
+ $order_field = '(total_points+5)/(total_votes+1)';
+ break;
+ case 'download':
+ $order_field = 'total_download';
+ break;
+ case 'name':
+ default:
+ $order = 'name';
+ $order_field = 'name';
+ }
+ $order_mode = $order_mode=='desc'?'desc':'asc';
+ $order_mode = $order_mode=='desc'?'desc':'asc';
+
+ if($text==''){
+ $result['total_pbis'] = 0;
+ $this->display->assign('pbis', array());
+ } else {
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'name', 'operator'=>'LIKE', 'value'=>'%'.$text.'%');
+ list($result['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
+ $this->display->assign('pbis', $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'), array(), ($current_page*$pbis_per_page).','.$pbis_per_page));
+ }
+
+ $this->display->assign('result', $result);
+ $this->display->assign('order', $order);
+ $this->display->assign('order_mode', $order_mode);
+ $this->display->assign('pbis_per_page', $pbis_per_page);
+ $this->display->assign('current_page', $current_page);
+ $this->display->assign('breadcrumb_text', htmlentities($text));
+
+ $this->display->assign('pbi', load_library('lang')->get('search_page_title'));
+ $this->display->assign('title', load_library('lang')->get('search_page_title'));
+ $this->display('search');
+
+ }
+
+ /************************************************
+ * ADMINISTRATION PART
+ ************************************************/
+ private function _get_redirect_messages($key='', $uri=''){
+ if($key=='') return '';
+ $messages['home'] = sprintf(load_library('lang')->get('redirect_home'),$this->display->get('home_uri'));
+ $messages['previous'] = sprintf(load_library('lang')->get('redirect_home'),$uri);
+
+ if(!isset($messages[$key])) return '';
+ else return $messages[$key];
+ }
+
+ public function web_admin(){
+ if(!$this->display->get('is_logged')){
+ $this->display->assign('task','login');
+ $this->web_admin_login();
+ } else {
+ $task = $this->uri->get_num(3);
+ if(method_exists($this,'web_admin_'.$task) && is_callable(array($this,'web_admin_'.$task))){
+ $this->display->assign('task',$task);
+ $this->{'web_admin_'.$task}();
+ } else {
+ $this->display->assign('task','home');
+ $this->web_home();
+ }
+ }
+ }
+
+ public function web_admin_login(){
+ $this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
+ $this->display->assign('title', load_library('lang')->get('login_page_title'));
+ $user = '';
+ if(!$this->cookie_check()){
+ $this->display->assign('error',load_library('lang')->get('login_error_cookies'));
+ }elseif(isset($_POST['username']) && isset($_POST['pws'])){
+ $user = $_POST['username'];
+ $ret = $this->permissions->login($user, $_POST['pws']);
+ if($ret===false){
+ $this->display->assign('error',load_library('lang')->get('login_failed'));
+ } else {
+ $this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
+ return true;
+ }
+ }
+ $this->display->assign('username',$user);
+ $this->display('login');
+ }
+
+ public function web_register(){
+ $this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
+ $user = '';
+ $email = '';
+ if(isset($_POST['username']) && isset($_POST['email'])){
+ $verification =& load_library('verification');
+ $user = $_POST['username'];
+ $email = $_POST['email'];
+ $vemail = $_POST['vemail'];
+ $error = array();
+ if($email!=$vemail){
+ $this->display->assign('error',load_library('lang')->get('registration_error_email_verification'));
+ } elseif(!$verification->email($email)){
+ $this->display->assign('error',load_library('lang')->get('registration_error_email_not_valid'));
+ } elseif(!$verification->alphanum($user)){
+ $this->display->assign('error',load_library('lang')->get('registration_error_user_alphanum'));
+ } elseif($this->permissions->user_exists($user)){
+ $this->display->assign('error',load_library('lang')->get('registration_error_user_exists'));
+ } else {
+ $ret = $this->permissions->register($user, $email);
+ if($ret===false){
+ $this->display->assign('error',load_library('lang')->get('registration_error_generic'));
+ } else {
+ $this->redirect($this->display->get('home_uri'), load_library('lang')->get('registration_success').' '.$this->_get_redirect_messages('home'), 10, true, 'pbidir');
+ return true;
+ }
+ }
+ }
+ $this->display->assign('title', load_library('lang')->get('registration_page_title'));
+ $this->display->assign('username',$user);
+ $this->display->assign('email',$email);
+ $this->display('registration');
+ }
+
+ public function web_admin_logout(){
+ $this->permissions->logout();
+ $this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_logout_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
+ }
+ /************************************************
+ * COMMENTS
+ ************************************************/
+ public function web_show_comment_form(){
+ $this->display->assign('comment_to_uri',$this->uri->create_uri(array(TASK_KEY=>'save_comment')).'/'.$this->uri->get_num(3));
+ $this->display('comment/form',false);
+ }
+
+ public function web_admin_delete_comment(){
+ $this->config->set('display_headers',array('Content-Type'=> 'text/plain')); //text/plain = only text file
+ $this->display->start();
+ if($this->pbi->delete_comment($this->uri->get_num(4),$this->uri->get_num(5))){
+ echo 'success';
+ } else {
+ echo 'Problems Deleting comment #'.$this->uri->get_num(5).' from pbi #'.$this->uri->get_num(4);
+ }
+ $this->display->end();
+ }
+
+ public function web_save_comment(){
+ //save the comment
+ $comment = trim($_POST['pbi_comment']);
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+ $filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+ $pbi = $this->pbi->get_record($filters)->get_info();
+ if($this->ajax){
+ $this->config->set('display_headers',array('Content-Type'=> 'text/xml')); //text/xml = xml file
+ } else {
+ $uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
+ }
+ if($this->permissions->can('pbi_comment')){
+ if($comment!='' && $this->pbi->add_comment($pbi['id'], htmlentities($comment, ENT_COMPAT, 'UTF-8'), $this->permissions->get('id',''),$this->permissions->get('user',''), $this->permissions->IP())!==false){
+ if($this->ajax){
+ $xml = array('message'=>array(
+ 'error' => '',
+ 'cid' => $this->pbi->db->insert_id(),
+ 'user' => $this->permissions->get('user',''),
+ 'body' => htmlentities($comment, ENT_COMPAT, 'UTF-8'),
+ 'date' => load_library('format')->datetime(),
+ )
+ );
+ } else {
+ $this->redirect($uri, 'Comment Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+ }
+ } else {
+ if($this->ajax){
+ $xml = array('message'=>array('error' => 'Problems saving your comment! Try Again later!'));
+ } else {
+ $this->redirect($uri, 'Problems saving your comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+ }
+ }
+ } else {
+ if($this->ajax){
+ $xml = array('message'=>array('error' => 'You do not have permissions to send a comment !!'));
+ } else {
+ $this->redirect($uri, 'You do not have permissions to send a comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+ }
+ }
+ if($this->ajax){
+ $this->display->assign('xml',$xml);
+ $this->display('xml',false);
+ }
+ }
+}
?>
\ No newline at end of file
Modified: websites/pbidir.com/bibivu/lib/pbi.php
===================================================================
--- websites/pbidir.com/bibivu/lib/pbi.php 2008-03-01 13:50:46 UTC (rev 1498)
+++ websites/pbidir.com/bibivu/lib/pbi.php 2008-03-01 16:27:50 UTC (rev 1499)
@@ -126,7 +126,7 @@
);
$filters = array();
$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $tmps = $this->get_raw($filters, array('name'),array('name'), '','licence');
+ $tmps = $this->get_raw($filters, array('name'),array(), '','licence');
$values = array();
foreach($tmps as $tmp){
$values[] = $tmp['id'].','.$tmp['name'];
Modified: websites/pbidir.com/bibivu/lib/permissions.php
===================================================================
--- websites/pbidir.com/bibivu/lib/permissions.php 2008-03-01 13:50:46 UTC (rev 1498)
+++ websites/pbidir.com/bibivu/lib/permissions.php 2008-03-01 16:27:50 UTC (rev 1499)
@@ -1,261 +1,265 @@
-<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
-// ------------------------------------------------------------------------
-class permissions extends table_prototype{
- private $user = array(); //current user
- private $timelogged = 'd'; //parameter for the function date. This will be used to keep a user logged in for this spam of time
- private $cookies;
- private $perm_item = array();
-
- /**
- * Initialize the default class
- *
- * @access private
- * @return void
- */
- public function __construct(){
- parent::__construct();
- if(isset($_SESSION['user'])) $this->user['user'] = $_SESSION['user'];
-
- $this->cookies =& load_library('cookies');
-
-// $table_prototype =& load_library('table_prototype');
-// $this->admin = clone $table_prototype;
- $this->set_table_name('user');
- $this->_fill_user_info();
- }
-
- private function _fill_user_info(){
- //check from sessions:
- if(isset($_SESSION['user_info'])){
- $this->user = $_SESSION['user_info'];
- } elseif($this->cookies->get('user')!=''){
- $filters = array(
- array('field'=>'user', 'operator'=>'LIKE', 'value'=>$this->cookies->get('user')),
- );
- $this->user = $this->select()->field('*')->where($filters)->do_db()->db->fetch_array($this->last_result());
- //and now the current group information
- if(isset($this->user['group_id'])){
- $filters = array(
- array('field'=>'id', 'operator'=>'=', 'value'=>$this->user['group_id']),
- );
-// $this->user['group'] = $this->select()->from('user_group')->field(array('id','code','name','BIN(`read`) `read`','BIN(`write`) `write`','BIN(`delete`) `delete`'))->where($filters)->do_db()->db->fetch_array($this->last_result());
- $this->user['group'] = $this->select()->from('group')->field(array('id','code','name'))->where($filters)->do_db()->db->fetch_array($this->last_result());
- $_SESSION['user_info'] = $this->user;
- }
- }
- }
-
- /**
- * Check if a username is logged in
- *
- * @access public
- * @retusn boolean
- */
- public function is_logged(){
- if(!isset($this->user['user'])){
- $this->_fill_user_info();
- }
- if(!isset($this->user['user']) || $this->user['user']!=$this->cookies->get('user')){
- return false;
- }
- return $this->cookies->get('cu')==$this->crypt_username($this->user['user']);
- }
-
- private function crypt_username($user){
- //timelogged should be a parameter that the function date will be able to use
- return preg_replace('/[^a-zA-Z0-9]/','',md5($user.date($this->timelogged)));
- }
-
- public function timelogged($timelogged='d'){
- $this->timelogged = $timelogged;
- }
- public function login($user, $pws){
- $filters = array(
- array('field'=>'user', 'operator'=>'LIKE', 'value'=>$user),
- );
-
- $tmp = $this->select()->field('id')->field('pws')->field('status')->field('user')->where($filters)->do_db()->db->fetch_array($this->last_result());
- if($tmp===false || $tmp['status']=='blocked' || $tmp['pws'] != md5($pws)){
- return false;
- } else {
- //need to set the cookies
- $this->cookies->set('user',$tmp['user']);
- $this->cookies->set('cu',$this->crypt_username($tmp['user']));
- $this->user['user'] = $user;
-
- $filters = array(
- array('field'=>'id', 'operator'=>'=', 'value'=>$tmp['id']),
- );
-
- $tmp = $this->update()->set('date_last_login', 'NOW()', true)->where($filters)->do_db();
- return true;
- }
- }
-
- public function change_pws($user, $pws){
- $filters = array(
- array('field'=>'user', 'operator'=>'LIKE', 'value'=>$user),
- );
- return $this->update()->set('pws', md5($pws))->where($filters)->do_db();
- }
-
- public function register($user, $email){
- //generating a random passowrd
- //10 chars should be enough
- $ret = $this->insert()->set('user', $user)->set('email',$email)->do_db();
- if($ret){
- $pws = substr(strtolower(md5(microtime().$user)),0,10);
- //need to send an email
- $mail =& load_library('email');
- $mail->AddAddress($email);
- $mail->From = 'reg at pbidir.com';
- $mail->FromName = 'pbiDir Registration';
- $mail->Subject = '[pbiDir] Registration';
- $mail->Body = $user.', welcome in pbiDir, you PC-BSD software'."\n\n".
- 'This is the password that you need to login into the pbidir website:'."\n".
- ' '.$pws."\n\n".
- 'Please Remember that the password is case sensitive!!'."\n\n".
- 'pbiDIR Staff';
- $mail->Send();
- return $this->change_pws($user, $pws);
- }
- }
-
- public function logout(){
- // $this->cookies->delete('cu');
- // $this->cookies->delete('user');
- $this->cookies->delete_all();
- unset($_SESSION['user_info']);
- }
-
- public function get_user_group_info(){
- //this returns all the info about the current group
- if(!isset($this->user['group'])){
- $this->_fill_user_info();
- }
- return isset($this->user['group'])?$this->user['group']:false;
- }
-
- public function get_user_info(){
- //this returns all the info about the current user
- if(!isset($this->user)){
- $this->_fill_user_info();
- }
- return $this->user;
- }
-
- public function is_root(){
- if(!$this->is_logged() ||
- (!isset($this->user['group']) && !$this->get_user_group_info())
- ) return false; //no group selected
- if($this->user['status'] != 'active') return false;
- return $this->user['group']['code']=='root';
- }
- public function can($item, $what='read', $owner = array()){
- if(!$this->is_logged() ||
- (!isset($this->user['group']) && !$this->get_user_group_info())
- ) return false; //no group selected
- if($this->user['status'] != 'active') return false;
- if($this->user['group']['code']=='root'){
- //can do everything
- return true;
- } else {
- $what = strtolower($what);
- if(!in_array($what,array('read', 'write', 'delete'))) $what = 'read';
- if(!isset($this->perm_item[$this->user['group']['code']][$item][$what])){
- $filters = array(
- // array('field'=>'active', 'operator'=>'=', 'value'=>'y'),
- array('field'=>'group_code', 'operator'=>'=', 'value'=>$this->user['group']['code']),
- array('field'=>'permission_item_code', 'operator'=>'=', 'value'=>$item),
- );
- list($perm) = $this->select()->field('`'.$what.'`')->from('permission_item_group')->where($filters)->do_db()->db->fetch_row($this->last_result());
- $this->perm_item[$this->user['group']['code']][$item][$what] = $perm;
- } else {
- $perm = $this->perm_item[$this->user['group']['code']][$item][$what];
- }
-// var_dump($item.$what.$perm,$owner);
- if($perm==0) return false; //NO
- if($perm==2) return true; //ALL
- if($perm==1) { //OWNED
- if(is_array($owner) && !empty($owner) &&
- isset($owner['table']) && $owner['table']!='' &&
- isset($owner['field']) && $owner['field']!='' &&
- isset($owner['field_id']) && $owner['field_id']!='' &&
- isset($owner['id']) && $owner['id']>0
- ){
- //check if I can modify it for ownership
- $filters = array(
- array('field'=>$owner['field'], 'operator'=>'=', 'value'=>$this->user['id']),
- array('field'=>$owner['field_id'], 'operator'=>'=', 'value'=>$owner['id']),
- );
- list($field_id) = $this->select()->field($owner['field_id'])->from($owner['table'])->where($filters)->do_db()->db->fetch_row($this->last_result());
- return $field_id==$owner['id'];
- } else {
- //only owned, but there is not ownership on those items
- return false;
- }
- }
- //should not be here
- return false;
- }
- }
-
- public function get($field='', $default=NULL){
- if($field==''){
- return $this->get_info();
- }
- return isset($this->user[$field])?$this->user[$field]:$default;
- }
-
- /**
- * Returns an ASCII string containing
- * the binary representation of the input data .
- **/
- private function _str2bin($str, $mode=0) {
- $out = false;
- for($a=0; $a < strlen($str); $a++) {
- $dec = ord(substr($str,$a,1));
- $bin = '';
- for($i=7; $i>=0; $i--) {
- if ( $dec >= pow(2, $i) ) {
- $bin .= "1";
- $dec -= pow(2, $i);
- } else {
- $bin .= "0";
- }
- }
- /* Default-mode */
- if ( $mode == 0 ) $out .= $bin;
- /* Human-mode (easy to read) */
- if ( $mode == 1 ) $out .= $bin . " ";
- /* Array-mode (easy to use) */
- if ( $mode == 2 ) $out[$a] = $bin;
- }
- return $out;
- }
-
- public function user_exists($user){
- $filters = array(
- array('field'=>'user', 'operator'=>'LIKE', 'value'=>$user),
- );
- $tmp = $this->select()->field('id')->where($filters)->do_db()->db->fetch_array($this->last_result());
- return isset($tmp['id']);
- }
-
- public function IP(){
- if(!isset($this->IP) || $this->IP==''){
- $tmp = array();
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) {
- $tmp += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
- } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $tmp[] = trim($_SERVER['HTTP_X_FORWARDED_FOR']);
- }elseif(isset($_SERVER['HTTP_CLIENT_IP'])) {
- $tmp[] = trim($_SERVER['HTTP_CLIENT_IP']);
- }
- $tmp[] = trim($_SERVER['REMOTE_ADDR']);
- $this->IP = trim(str_replace('unknown','',strtolower(implode("\n",$tmp))));
- }
- return $this->IP;
- }
-}
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+// ------------------------------------------------------------------------
+class permissions extends table_prototype{
+ private $user = array(); //current user
+ private $timelogged = 'd'; //parameter for the function date. This will be used to keep a user logged in for this spam of time
+ private $cookies;
+ private $perm_item = array();
+
+ /**
+ * Initialize the default class
+ *
+ * @access private
+ * @return void
+ */
+ public function __construct(){
+ parent::__construct();
+ if(isset($_SESSION['user'])) $this->user['user'] = $_SESSION['user'];
+
+ $this->cookies =& load_library('cookies');
+
+// $table_prototype =& load_library('table_prototype');
+// $this->admin = clone $table_prototype;
+ $this->set_table_name('user');
+ $this->_fill_user_info();
+ }
+
+ private function _fill_user_info($reset = false){
+ //check from sessions:
+ if(isset($_SESSION['user_info']) && $reset===false){
+ $this->user = $_SESSION['user_info'];
+ } elseif($this->cookies->get('user')!=''){
+ $filters = array(
+ array('field'=>'user', 'operator'=>'LIKE', 'value'=>$this->cookies->get('user')),
+ );
+ $this->user = $this->select()->field('*')->where($filters)->do_db()->db->fetch_array($this->last_result());
+ //and now the current group information
+ if(isset($this->user['group_id'])){
+ $filters = array(
+ array('field'=>'id', 'operator'=>'=', 'value'=>$this->user['group_id']),
+ );
+// $this->user['group'] = $this->select()->from('user_group')->field(array('id','code','name','BIN(`read`) `read`','BIN(`write`) `write`','BIN(`delete`) `delete`'))->where($filters)->do_db()->db->fetch_array($this->last_result());
+ $this->user['group'] = $this->select()->from('group')->field(array('id','code','name'))->where($filters)->do_db()->db->fetch_array($this->last_result());
+ $_SESSION['user_info'] = $this->user;
+ }
+ }
+ }
+
+ public function reset_user_info(){
+ $this->_fill_user_info(true);
+ }
+
+ /**
+ * Check if a username is logged in
+ *
+ * @access public
+ * @retusn boolean
+ */
+ public function is_logged(){
+ if(!isset($this->user['user'])){
+ $this->_fill_user_info();
+ }
+ if(!isset($this->user['user']) || $this->user['user']!=$this->cookies->get('user')){
+ return false;
+ }
+ return $this->cookies->get('cu')==$this->crypt_username($this->user['user']);
+ }
+
+ private function crypt_username($user){
+ //timelogged should be a parameter that the function date will be able to use
+ return preg_replace('/[^a-zA-Z0-9]/','',md5($user.date($this->timelogged)));
+ }
+
+ public function timelogged($timelogged='d'){
+ $this->timelogged = $timelogged;
+ }
+ public function login($user, $pws){
+ $filters = array(
+ array('field'=>'user', 'operator'=>'LIKE', 'value'=>$user),
+ );
+
+ $tmp = $this->select()->field('id')->field('pws')->field('status')->field('user')->where($filters)->do_db()->db->fetch_array($this->last_result());
+ if($tmp===false || $tmp['status']=='blocked' || $tmp['pws'] != md5($pws)){
+ return false;
+ } else {
+ //need to set the cookies
+ $this->cookies->set('user',$tmp['user']);
+ $this->cookies->set('cu',$this->crypt_username($tmp['user']));
+ $this->user['user'] = $user;
+
+ $filters = array(
+ array('field'=>'id', 'operator'=>'=', 'value'=>$tmp['id']),
+ );
+
+ $tmp = $this->update()->set('date_last_login', 'NOW()', true)->where($filters)->do_db();
+ return true;
+ }
+ }
+
+ public function change_pws($user, $pws){
+ $filters = array(
+ array('field'=>'user', 'operator'=>'LIKE', 'value'=>$user),
+ );
+ return $this->update()->set('pws', md5($pws))->where($filters)->do_db();
+ }
+
+ public function register($user, $email){
+ //generating a random passowrd
+ //10 chars should be enough
+ $ret = $this->insert()->set('user', $user)->set('email',$email)->do_db();
+ if($ret){
+ $pws = substr(strtolower(md5(microtime().$user)),0,10);
+ //need to send an email
+ $mail =& load_library('email');
+ $mail->AddAddress($email);
+ $mail->From = 'reg at pbidir.com';
+ $mail->FromName = 'pbiDir Registration';
+ $mail->Subject = '[pbiDir] Registration';
+ $mail->Body = $user.', welcome in pbiDir, you PC-BSD software'."\n\n".
+ 'This is the password that you need to login into the pbidir website:'."\n".
+ ' '.$pws."\n\n".
+ 'Please Remember that the password is case sensitive!!'."\n\n".
+ 'pbiDIR Staff';
+ $mail->Send();
+ return $this->change_pws($user, $pws);
+ }
+ }
+
+ public function logout(){
+ // $this->cookies->delete('cu');
+ // $this->cookies->delete('user');
+ $this->cookies->delete_all();
+ unset($_SESSION['user_info']);
+ }
+
+ public function get_user_group_info(){
+ //this returns all the info about the current group
+ if(!isset($this->user['group'])){
+ $this->_fill_user_info();
+ }
+ return isset($this->user['group'])?$this->user['group']:false;
+ }
+
+ public function get_user_info(){
+ //this returns all the info about the current user
+ if(!isset($this->user)){
+ $this->_fill_user_info();
+ }
+ return $this->user;
+ }
+
+ public function is_root(){
+ if(!$this->is_logged() ||
+ (!isset($this->user['group']) && !$this->get_user_group_info())
+ ) return false; //no group selected
+ if($this->user['status'] != 'active') return false;
+ return $this->user['group']['code']=='root';
+ }
+ public function can($item, $what='read', $owner = array()){
+ if(!$this->is_logged() ||
+ (!isset($this->user['group']) && !$this->get_user_group_info())
+ ) return false; //no group selected
+ if($this->user['status'] != 'active') return false;
+ if($this->user['group']['code']=='root'){
+ //can do everything
+ return true;
+ } else {
+ $what = strtolower($what);
+ if(!in_array($what,array('read', 'write', 'delete'))) $what = 'read';
+ if(!isset($this->perm_item[$this->user['group']['code']][$item][$what])){
+ $filters = array(
+ // array('field'=>'active', 'operator'=>'=', 'value'=>'y'),
+ array('field'=>'group_code', 'operator'=>'=', 'value'=>$this->user['group']['code']),
+ array('field'=>'permission_item_code', 'operator'=>'=', 'value'=>$item),
+ );
+ list($perm) = $this->select()->field('`'.$what.'`')->from('permission_item_group')->where($filters)->do_db()->db->fetch_row($this->last_result());
+ $this->perm_item[$this->user['group']['code']][$item][$what] = $perm;
+ } else {
+ $perm = $this->perm_item[$this->user['group']['code']][$item][$what];
+ }
+// var_dump($item.$what.$perm,$owner);
+ if($perm==0) return false; //NO
+ if($perm==2) return true; //ALL
+ if($perm==1) { //OWNED
+ if(is_array($owner) && !empty($owner) &&
+ isset($owner['table']) && $owner['table']!='' &&
+ isset($owner['field']) && $owner['field']!='' &&
+ isset($owner['field_id']) && $owner['field_id']!='' &&
+ isset($owner['id']) && $owner['id']>0
+ ){
+ //check if I can modify it for ownership
+ $filters = array(
+ array('field'=>$owner['field'], 'operator'=>'=', 'value'=>$this->user['id']),
+ array('field'=>$owner['field_id'], 'operator'=>'=', 'value'=>$owner['id']),
+ );
+ list($field_id) = $this->select()->field($owner['field_id'])->from($owner['table'])->where($filters)->do_db()->db->fetch_row($this->last_result());
+ return $field_id==$owner['id'];
+ } else {
+ //only owned, but there is not ownership on those items
+ return false;
+ }
+ }
+ //should not be here
+ return false;
+ }
+ }
+
+ public function get($field='', $default=NULL){
+ if($field==''){
+ return $this->get_info();
+ }
+ return isset($this->user[$field])?$this->user[$field]:$default;
+ }
+
+ /**
+ * Returns an ASCII string containing
+ * the binary representation of the input data .
+ **/
+ private function _str2bin($str, $mode=0) {
+ $out = false;
+ for($a=0; $a < strlen($str); $a++) {
+ $dec = ord(substr($str,$a,1));
+ $bin = '';
+ for($i=7; $i>=0; $i--) {
+ if ( $dec >= pow(2, $i) ) {
+ $bin .= "1";
+ $dec -= pow(2, $i);
+ } else {
+ $bin .= "0";
+ }
+ }
+ /* Default-mode */
+ if ( $mode == 0 ) $out .= $bin;
+ /* Human-mode (easy to read) */
+ if ( $mode == 1 ) $out .= $bin . " ";
+ /* Array-mode (easy to use) */
+ if ( $mode == 2 ) $out[$a] = $bin;
+ }
+ return $out;
+ }
+
+ public function user_exists($user){
+ $filters = array(
+ array('field'=>'user', 'operator'=>'LIKE', 'value'=>$user),
+ );
+ $tmp = $this->select()->field('id')->where($filters)->do_db()->db->fetch_array($this->last_result());
+ return isset($tmp['id']);
+ }
+
+ public function IP(){
+ if(!isset($this->IP) || $this->IP==''){
+ $tmp = array();
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) {
+ $tmp += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
+ } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $tmp[] = trim($_SERVER['HTTP_X_FORWARDED_FOR']);
+ }elseif(isset($_SERVER['HTTP_CLIENT_IP'])) {
+ $tmp[] = trim($_SERVER['HTTP_CLIENT_IP']);
+ }
+ $tmp[] = trim($_SERVER['REMOTE_ADDR']);
+ $this->IP = trim(str_replace('unknown','',strtolower(implode("\n",$tmp))));
+ }
+ return $this->IP;
+ }
+}
?>
\ No newline at end of file
Modified: websites/pbidir.com/bibivu/lib/user.php
===================================================================
--- websites/pbidir.com/bibivu/lib/user.php 2008-03-01 13:50:46 UTC (rev 1498)
+++ websites/pbidir.com/bibivu/lib/user.php 2008-03-01 16:27:50 UTC (rev 1499)
@@ -1,238 +1,250 @@
-<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
-// ------------------------------------------------------------------------
-class user extends table_prototype{
- /**
- * Initialize the default class
- *
-` * @access private
- * @return void
- */
- public function __construct(){
- parent::__construct();
- $this->set_table_name('user');
- }
-
- public function get_related_tables(){
- //this is the table that relate all the tables with each other
-
- if($this->related==array()){
- $related = array();
- if(load_library('permissions')->can('pbi','write')){
- $related[] = array( 'table' => 'pbi',
- 'field' => 'user_id',
- 'main_field' => 'id',
- 'show' => 'list', //field, list
- 'name' => 'PBI',
- 'autoopen' => false,
- 'relation_table'=> array(),
- );
- }
- $related[] = array( 'table' => 'pbi',
- 'field' => 'id',
- 'main_field' => 'pbi_id',
- 'show' => 'list', //field, list
- 'name' => 'Subscriptions',
- 'autoopen' => false,
- 'relation_table'=> array(
- 'table' => 'subscriptions',
- 'field' => 'user_id',
- 'main_field' => 'id',
- ),
- );
- $this->related = $related;
- }
- return $this->related;
- }
-
- public function get_fields(){
- if($this->fields==array()){
-
- $fields['id'] = array( 'show' => false,
- 'view_link' => false,
- 'edit' => false,
- 'type' => 'number',
- 'length'=> NULL,
- 'values'=> NULL,
- 'text' => 'id',
- 'required' => NULL,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['name'] = array( 'show' => true,
- 'view_link'=>true,
- 'edit' => true,
- 'type' => 'string',
- 'length'=> 50,
- 'values'=> NULL,
- 'text' => 'Name',
- 'required' => false,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['user'] = array( 'show' => true,
- 'view_link'=>true,
- 'edit' => load_library('permissions')->can('user','write'),
- 'type' => 'string',
- 'length'=> 30,
- 'values'=> NULL,
- 'text' => 'User',
- 'required' => true,
- 'post' => load_library('permissions')->can('user','write'),
- 'default' => NULL,
- 'image' => false,
- );
- $fields['pws'] = array( 'show' => false,
- 'view_link'=>true,
- 'edit' => true,
- 'type' => 'password',
- 'length'=> 30,
- 'values'=> NULL,
- 'text' => 'Password',
- 'required' => false,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['vpws'] = array( 'show' => false,
- 'view_link'=>true,
- 'edit' => true,
- 'type' => 'password',
- 'length'=> 30,
- 'values'=> NULL,
- 'text' => 'Verify Password',
- 'required' => false,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['email'] = array( 'show' => true,
- 'view_link'=>true,
- 'edit' => true,
- 'type' => 'email',
- 'length'=> 50,
- 'values'=> NULL,
- 'text' => 'Email',
- 'required' => true,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['status'] = array( 'show' => true,
- 'view_link' => false,
- 'edit' => load_library('permissions')->can('user','write'),
- 'type' => 'enum',
- 'length'=> NULL,
- 'values'=> 'pending,Pending|active,Active|blocked,Blocked',
- 'text' => 'Status',
- 'required' => NULL,
- 'post' => load_library('permissions')->can('user','write'),
- 'default' => 'active',
- 'image' => false,
- );
- $filters = array();
- $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
- $tmps = $this->get_raw($filters, array('name'),array(), '','group');
- $values = array();
- foreach($tmps as $tmp){
- $values[] = $tmp['id'].','.$tmp['name'];
- }
- $fields['group_id'] = array( 'show' => true,
- 'view_link' => false,
- 'edit' => load_library('permissions')->can('user','write'),
- 'type' => 'enum',
- 'length'=> NULL,
- 'values'=> implode('|',$values),
- 'text' => 'Group',
- 'required' => NULL,
- 'post' => load_library('permissions')->can('user','write'),
- 'default' => 'y',
- 'image' => false,
- );
- $fields['date_last_login'] = array( 'show' => false,
- 'view_link' => false,
- 'edit' => false,
- 'type' => 'date',
- 'length'=> NULL,
- 'values'=> NULL,
- 'text' => 'Last Login',
- 'required' => NULL,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['date_added'] = array( 'show' => false,
- 'view_link' => false,
- 'edit' => false,
- 'type' => 'date',
- 'length'=> NULL,
- 'values'=> NULL,
- 'text' => 'Date Added',
- 'required' => NULL,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $fields['date_modified'] = array( 'show' => false,
- 'view_link' => false,
- 'edit' => false,
- 'type' => 'date',
- 'length'=> NULL,
- 'values'=> NULL,
- 'text' => 'Date Modified',
- 'required' => NULL,
- 'post' => true,
- 'default' => NULL,
- 'image' => false,
- );
- $this->fields = $fields;
- }
- return $this->fields;
- }
-
- public function get_all($where=array(), $orders=array(), $group=array(), $limit='', $from='', $join = array(), $xtrfields = array()){
- $fields = $this->get_fields();
- $str = '^('.implode('|', array_keys($fields)).').?(ASC|DESC)?$';
- foreach($orders as $key=>$order){
- if(!eregi($str,$order)){
- $orders[$key] = 'name';
- }
- }
- return parent::get_all($where, $orders, $group, $limit, $from, $join, $xtrfields);
- }
-
- public function get_info(){
- //I only format all the output
- $return = parent::get_info();
- $return['pws'] = '';
- $this->current = $return;
- return $return;
- }
-
- public function edit($id, $tt_post){
- if(isset($tt_post['pws']) && $tt_post['pws']!=''){
- if(!isset($tt_post['vpws']) || $tt_post['pws']!=$tt_post['vpws']){
- return 'Please Verify The Password !!';
- }
- $tt_post['pws'] = md5($tt_post['pws']);
- } else {
- unset($tt_post['pws']); //no password to be stored
- }
- unset($tt_post['vpws']);
- return parent::edit($id, $tt_post);
- }
- public function add($tt_post){
- if(isset($tt_post['pws']) && $tt_post['pws']!=''){
- if(!isset($tt_post['vpws']) || $tt_post['pws']!=$tt_post['vpws']){
- return 'Please Verify The Password!!';
- }
- $tt_post['pws'] = md5($tt_post['pws']);
- } else {
- unset($tt_post['pws']); //no password to be stored
- }
- unset($tt_post['vpws']);
- return parent::add($tt_post);
- }
-}
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+// ------------------------------------------------------------------------
+class user extends table_prototype{
+ /**
+ * Initialize the default class
+ *
+` * @access private
+ * @return void
+ */
+ public function __construct(){
+ parent::__construct();
+ $this->set_table_name('user');
+ }
+
+ public function get_related_tables(){
+ //this is the table that relate all the tables with each other
+
+ if($this->related==array()){
+ $related = array();
+ if(load_library('permissions')->can('pbi','write')){
+ $related[] = array( 'table' => 'pbi',
+ 'field' => 'user_id',
+ 'main_field' => 'id',
+ 'show' => 'list', //field, list
+ 'name' => 'PBI',
+ 'autoopen' => false,
+ 'relation_table'=> array(),
+ );
+ }
+ $related[] = array( 'table' => 'pbi',
+ 'field' => 'id',
+ 'main_field' => 'pbi_id',
+ 'show' => 'list', //field, list
+ 'name' => 'Subscriptions',
+ 'autoopen' => false,
+ 'relation_table'=> array(
+ 'table' => 'subscriptions',
+ 'field' => 'user_id',
+ 'main_field' => 'id',
+ ),
+ );
+ $this->related = $related;
+ }
+ return $this->related;
+ }
+
+ public function get_fields(){
+ if($this->fields==array()){
+
+ $fields['id'] = array( 'show' => false,
+ 'view_link' => false,
+ 'edit' => false,
+ 'type' => 'number',
+ 'length'=> NULL,
+ 'values'=> NULL,
+ 'text' => 'id',
+ 'required' => NULL,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['name'] = array( 'show' => true,
+ 'view_link'=>true,
+ 'edit' => true,
+ 'type' => 'string',
+ 'length'=> 50,
+ 'values'=> NULL,
+ 'text' => 'Name',
+ 'required' => false,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['user'] = array( 'show' => true,
+ 'view_link'=>true,
+ 'edit' => load_library('permissions')->can('user','write'),
+ 'type' => 'string',
+ 'length'=> 30,
+ 'values'=> NULL,
+ 'text' => 'User',
+ 'required' => true,
+ 'post' => load_library('permissions')->can('user','write'),
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['pws'] = array( 'show' => false,
+ 'view_link'=>true,
+ 'edit' => true,
+ 'type' => 'password',
+ 'length'=> 30,
+ 'values'=> NULL,
+ 'text' => 'Password',
+ 'required' => false,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['vpws'] = array( 'show' => false,
+ 'view_link'=>true,
+ 'edit' => true,
+ 'type' => 'password',
+ 'length'=> 30,
+ 'values'=> NULL,
+ 'text' => 'Verify Password',
+ 'required' => false,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['email'] = array( 'show' => true,
+ 'view_link'=>true,
+ 'edit' => true,
+ 'type' => 'email',
+ 'length'=> 50,
+ 'values'=> NULL,
+ 'text' => 'Email',
+ 'required' => true,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['lang'] = array( 'show' => true,
+ 'view_link' => false,
+ 'edit' => true,
+ 'type' => 'enum',
+ 'length'=> NULL,
+ 'values'=> 'en,Eglish|it,Italiano|es,Espanol',
+ 'text' => 'Language',
+ 'required' => NULL,
+ 'post' => true,
+ 'default' => 'en',
+ 'image' => false,
+ );
+ $fields['status'] = array( 'show' => true,
+ 'view_link' => false,
+ 'edit' => load_library('permissions')->can('user','write'),
+ 'type' => 'enum',
+ 'length'=> NULL,
+ 'values'=> 'pending,Pending|active,Active|blocked,Blocked',
+ 'text' => 'Status',
+ 'required' => NULL,
+ 'post' => load_library('permissions')->can('user','write'),
+ 'default' => 'active',
+ 'image' => false,
+ );
+ $filters = array();
+ $filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+ $tmps = $this->get_raw($filters, array('name'),array(), '','group');
+ $values = array();
+ foreach($tmps as $tmp){
+ $values[] = $tmp['id'].','.$tmp['name'];
+ }
+ $fields['group_id'] = array( 'show' => true,
+ 'view_link' => false,
+ 'edit' => load_library('permissions')->can('user','write'),
+ 'type' => 'enum',
+ 'length'=> NULL,
+ 'values'=> implode('|',$values),
+ 'text' => 'Group',
+ 'required' => NULL,
+ 'post' => load_library('permissions')->can('user','write'),
+ 'default' => 'y',
+ 'image' => false,
+ );
+ $fields['date_last_login'] = array( 'show' => false,
+ 'view_link' => false,
+ 'edit' => false,
+ 'type' => 'date',
+ 'length'=> NULL,
+ 'values'=> NULL,
+ 'text' => 'Last Login',
+ 'required' => NULL,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['date_added'] = array( 'show' => false,
+ 'view_link' => false,
+ 'edit' => false,
+ 'type' => 'date',
+ 'length'=> NULL,
+ 'values'=> NULL,
+ 'text' => 'Date Added',
+ 'required' => NULL,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $fields['date_modified'] = array( 'show' => false,
+ 'view_link' => false,
+ 'edit' => false,
+ 'type' => 'date',
+ 'length'=> NULL,
+ 'values'=> NULL,
+ 'text' => 'Date Modified',
+ 'required' => NULL,
+ 'post' => true,
+ 'default' => NULL,
+ 'image' => false,
+ );
+ $this->fields = $fields;
+ }
+ return $this->fields;
+ }
+
+ public function get_all($where=array(), $orders=array(), $group=array(), $limit='', $from='', $join = array(), $xtrfields = array()){
+ $fields = $this->get_fields();
+ $str = '^('.implode('|', array_keys($fields)).').?(ASC|DESC)?$';
+ foreach($orders as $key=>$order){
+ if(!eregi($str,$order)){
+ $orders[$key] = 'name';
+ }
+ }
+ return parent::get_all($where, $orders, $group, $limit, $from, $join, $xtrfields);
+ }
+
+ public function get_info(){
+ //I only format all the output
+ $return = parent::get_info();
+ $return['pws'] = '';
+ $this->current = $return;
+ return $return;
+ }
+
+ public function edit($id, $tt_post){
+ if(isset($tt_post['pws']) && $tt_post['pws']!=''){
+ if(!isset($tt_post['vpws']) || $tt_post['pws']!=$tt_post['vpws']){
+ return 'Please Verify The Password !!';
+ }
+ $tt_post['pws'] = md5($tt_post['pws']);
+ } else {
+ unset($tt_post['pws']); //no password to be stored
+ }
+ unset($tt_post['vpws']);
+ return parent::edit($id, $tt_post);
+ }
+ public function add($tt_post){
+ if(isset($tt_post['pws']) && $tt_post['pws']!=''){
+ if(!isset($tt_post['vpws']) || $tt_post['pws']!=$tt_post['vpws']){
+ return 'Please Verify The Password!!';
+ }
+ $tt_post['pws'] = md5($tt_post['pws']);
+ } else {
+ unset($tt_post['pws']); //no password to be stored
+ }
+ unset($tt_post['vpws']);
+ return parent::add($tt_post);
+ }
+}
?>
\ No newline at end of file
Modified: websites/pbidir.com/bibivu/slib/lang.php
===================================================================
--- websites/pbidir.com/bibivu/slib/lang.php 2008-03-01 13:50:46 UTC (rev 1498)
+++ websites/pbidir.com/bibivu/slib/lang.php 2008-03-01 16:27:50 UTC (rev 1499)
@@ -1,177 +1,173 @@
-<?php
-//this class is intended to help with the handling of the cookies
-
-class lang{
- private $config = array();
- private $words = array();
- private $loaded = array();
- public function __construct(){
- $this->config['lang'] = 'en';
- $cfg = load_class('config')->load_config('lang')->get('lang');
- if(is_array($cfg)){
- foreach($cfg as $key=>$value){
- $this->config[$key]=$value;
- }
- }
- }
-
- /**
- * Fetch an item from the COOKIE array
- *
- * @access public
- * @param string
- * @param bool
- * @return mixed
- */
- public function get($word, $default='', $lang=''){
- if($lang=='') $lang = $this->_detect_lang();
- if(!(isset($this->words[$lang][$word]) && $this->words[$lang][$word]!='')){
- //this language is not loaded
- $file = '';
- if(strpos($word,'_')>0){
- list($file, $word1) = explode('_', $word, 2);
- }
- $this->load_lang($lang, $file);
- }
- if(!(isset($this->words[$lang][$word]) && $this->words[$lang][$word]!='')){
- //nothing .. returning the default
- //to avoid to load the file over and over
- //I set the current key as the default
- $this->words[$lang][$word] = $default!=''?$default:$word;
- }
- return $this->words[$lang][$word];
- }
-
- public function load_lang($language, $file = ''){
- //reset language
- if($file=='') $file = 'common';
- $folder = ETCPATH.'lang/'.$language.'/';
- $lang_file = $folder.$file.'.lang'.EXT;
- if(file_exists($lang_file)){
- $lang = array();
- include_once($lang_file);
- foreach($lang as $key=>$value){
- $this->words[$language][($file!='common'?$file.'_':'').$key] = $value;
- }
- }
- //maybe later on add it to the cache
- }
-
- //PART OF THIS FUNCTION HAS BEEN GRABBED FROM PHPMYADMIN
- //and changed by fabrizio parrella
- /**
- * All the supported languages have to be listed in the array below.
- * 1. The key must be the "official" ISO 639 language code and, if required,
- * the dialect code. It can also contain some informations about the
- * charset (see the Russian case).
- * 2. The first of the values associated to the key is used in a regular
- * expression to find some keywords corresponding to the language inside two
- * environment variables.
- * These values contains:
- * - the "official" ISO language code and, if required, the dialect code
- * also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
- * dialects, 'zh[-_]tw' for Chinese traditional...);
- * - the '|' character (it means 'OR');
- * - the full language name.
- * 3. The last values associated to the key is the language code as defined by
- * the RFC1766. This will be used for the name of the folder for the language
- *
- * Beware that the sorting order (first values associated to keys by
- * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
- * traditional) must be detected before 'zh' (chinese simplified) for
- * example.
- *
- * When there are more than one charset for a language, we put the
- * first.
- *
- * For Russian, we put 1251 first, because MSIE does not accept 866
- * and users would not see anything.
- */
- private function _detect_lang(){
- $lang = '';
- if($this->config['detect']){
- if(isset($this->config['detected']) && $this->config['detected']!=''){
- $lang = $this->config['detected'];
- } else {
- $array_languages = array(
- 'af' => 'af|afrikaans',
- 'ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
- 'az' => 'az|azerbaijani',
- 'bg' => 'bg|bulgarian',
- 'bs' => 'bs|bosnian',
- 'ca' => 'ca|catalan',
- 'cs' => 'cs|czech',
- 'da' => 'da|danish',
- 'de' => 'de([-_][[:alpha:]]{2})?|german',
- 'el' => 'el|greek',
- 'en' => 'en([-_][[:alpha:]]{2})?|english',
- 'es' => 'es([-_][[:alpha:]]{2})?|spanish',
- 'et' => 'et|estonian',
- 'eu' => 'eu|basque',
- 'fa' => 'fa|persian',
- 'fi' => 'fi|finnish',
- 'fr' => 'fr([-_][[:alpha:]]{2})?|french',
- 'gl' => 'gl|galician',
- 'he' => 'he|hebrew',
- 'hi' => 'hi|hindi',
- 'hr' => 'hr|croatian',
- 'hu' => 'hu|hungarian',
- 'id' => 'id|indonesian',
- 'it' => 'it([-_][[:alpha:]]{2})?|italian',
- 'ja' => 'ja|japanese',
- 'ko' => 'ko|korean',
- 'ka' => 'ka|georgian',
- 'lt' => 'lt|lithuanian',
- 'lv' => 'lv|latvian',
- 'ms' => 'ms|malay',
- 'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
- 'no' => 'no|norwegian',
- 'pl' => 'pl|polish',
- 'pt-br' => 'pt[-_]br|brazilian portuguese',
- 'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
- 'ro' => 'ro|romanian',
- 'ru' => 'ru|russian',
- 'sk' => 'sk|slovak',
- 'sl' => 'sl|slovenian',
- 'sq' => 'sq|albanian',
- 'sr' => 'sr|serbian',
- 'sr-lat' => 'sr[-_]lat|serbian latin',
- 'sv' => 'sv|swedish',
- 'th' => 'th|thai',
- 'tr' => 'tr|turkish',
- 'uk' => 'uk|ukrainian',
- 'zh-tw' => 'zh[-_]tw|chinese traditional',
- 'zh' => 'zh|chinese simplified',
- );
- // Language is not defined yet :
- // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
- // variable
- if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- $accepted = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
- $acceptedCnt = count($accepted);
- for ($i = 0; $i < $acceptedCnt && $lang==''; $i++) {
- foreach($array_languages as $key => $value) {
- if (eregi('^('.$value.')(;q=[0-9]\\.[0-9])?$', $accepted[$i])) {
- $lang = $key;
- break;
- }
- }
- }
- }
- // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
- if ($lang == '' && !empty($_SERVER['HTTP_USER_AGENT'])) {
- foreach($array_languages as $key => $value) {
- if (eregi('(\(|\[|;[[:space:]])('.$value.')(;|\]|\))', $_SERVER['HTTP_USER_AGENT'])) {
- $lang = $key;
- break;
- }
- }
- }
- }
- }
- if(!in_array($lang