From 7df42c63e3bcdf7c4a697280a849b280d4149997 Mon Sep 17 00:00:00 2001 From: val19116 Date: Wed, 30 Mar 2016 12:14:36 -0400 Subject: [PATCH 01/18] ignore files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 619e492..2eabe5f 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *# .#* *.DS_Store +/.gitignore +/version.txt From 7c49e02c93238cf6b0eec0d68ae6afba04ffcd76 Mon Sep 17 00:00:00 2001 From: System Administrator Date: Wed, 6 Jul 2016 10:51:00 -0400 Subject: [PATCH 02/18] auth class correction to functions.inc --- lib/core/functions.inc.php | 215 +++++++++++-------------------------- 1 file changed, 61 insertions(+), 154 deletions(-) diff --git a/lib/core/functions.inc.php b/lib/core/functions.inc.php index 4f02a9a..18ca93f 100755 --- a/lib/core/functions.inc.php +++ b/lib/core/functions.inc.php @@ -776,162 +776,13 @@ function encode($input) { * @param string $access_group... * @return boolean returns true if the user is granted access to one or more of the specified access_groups, otherwise returns false */ - function auth() { - for ($i=0; $i < func_num_args(); $i++) { - - $arg = func_get_arg($i); - - $person_id = $_SESSION['login']['person_id']; - - if ( !$person_id ) return false; - if ( !$arg ) return true; - - // new method -- check the appropriate keytable on demand - if ( strpos($arg,':') ): - - return auth_person($arg, $person_id); - - // old method -- for backwards compatibility -- check the session for the desired access group (person.access_group) - else: - $arr = explode(',',$arg); - foreach ($arr as $arg): - if ( strpos(strtolower($_SESSION['login']['access_group']),strtolower($arg)) !== false ): - return true; - endif; - endforeach; - endif; - - }//for - return false; - }//function - - /** - - will return an auth function that uses those contraints - - value arguments for now only accept ['constant'] - - KEYS MUST BE SET - - constraints = array( - 'arg1' => $vars, // check contants - 'arg2' => $vars // dont check for constant - ); - */ - - function makeAuthFn($constraints) { - - static $results = array(); - - if (!is_assoc($constraints)) { - throw new Exception('constraints needs to be an associative array'); - } - - $constraint_hash = md5(serialize($constraints)); - - $trim_to_lower = function($str) { - return trim(strtolower($str)); - }; - - return function($access_level_str, $params = null) use($constraints, $constraint_hash, $trim_to_lower, &$results) { - - // set key for this auth_function if it doesnt exist - if (!array_key_exists($constraint_hash, $results)) { - $results[$constraint_hash] = array(); - } - - // make sure parms is an array regardless of what's given. - if (count($constraints) == 1) { - if (!is_array($params)) { - $params = array( reset(array_keys($constraints)) => $params); - } - } - - // generate where, look for constants if check_for_constant is true and the params are not defined - // return false if it isn't set, exit early - $where = array(); - foreach ($constraints as $constraint => $vars) { - if (!$params[$constraint]) { - if (!$vars['constant']) return false; - if (defined($vars['constant'])) { - $params[$constraint] = constant($vars['constant']); - } - if (!$params[$constraint]) return false; - } - $where[] = "{$constraint} = {$params[$constraint]}"; - } - - // make hash - $param_hash = md5(sprintf('%s:::%s', $access_level_str, serialize($params))); - - // if this has been computed for this page return the result - if (array_key_exists($param_hash, $results[$constraint_hash])) { - return $results[$constraint_hash][$param_hash]; - } - - $allowed = false; - $access_level_arr = explode(';', $access_level_str); - - foreach ($access_level_arr as $access_level) { - - $access = array_map($trim_to_lower, explode(':', $access_level, 2)); - $key_table = $access[0]; - - if (!$key_table) continue; - - $access_needed_arr = my_array_unique( - array_map($trim_to_lower, - explode(',', $access[1]) - ) - ); - - if ($access_needed_arr[0] == '*') { - $access_needed_arr = array(); - } - - $aql = " $key_table { id, access_group } "; - $rs = aql::select($aql, array( - 'where' => $where, - 'limit' => 1 - )); - - if (!$rs) continue; - - if (!$access_needed_arr) { - $allowed = true; - break; - } - - $granted = array_map($trim_to_lower, explode(',', $rs[0]['access_group'])); - foreach ($access_needed_arr as $needed) { - if (in_array($needed, $granted)) { - $allowed = true; - break 2; // break out of both loops if a match is found - } - } - - } - - // return and store value - return $results[$constraint_hash][$param_hash] = $allowed; - - }; - + function auth($params=null) { + return auth::permission($params); } - function auth_person( $access_level_str, $person_id=NULL ) { - - if (!$person_id) $person_id = $_SESSION['login']['person_id']; - if (strpos($access_level_str,'person:') !== false) $idField = 'id'; - else $idField = 'person_id'; - $auth_fn = makeAuthFn(array( - $idField=> array( - 'constant' => 'PERSON_ID' - ) - )); - return $auth_fn($access_level_str, $person_id); - - }//auth_person + function auth_person($access_level_str, $person_id=null) { + return auth::permission($access_level_str, $person_id); + } function login_person($person,$remember_me) { @@ -2066,3 +1917,59 @@ function getMimeTypes() 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', ); } + +class auth { + /** + * auth class + * + * Organization: Hotwire Communications + * Author: Harley Fischel + */ + public static function permission($params=null, $person_id=null) { + $params = trim($params); + if (empty($params)) return false; + if (empty($person_id)&&isset($_SESSION['login']['person_id'])) { + $person_id = $_SESSION['login']['person_id']; + } + + // old method support + if (!strpos($params,':')) { + $arr = explode(',',$params); + foreach ($arr as $arg) { + if (strpos(strtolower($_SESSION['login']['access_group']),strtolower($arg))!==false) return true; + } + return false; + } + + static $access, $key; + + // new method + $perms = explode(';',$params); + foreach($perms as $perm){ + list($group, $granted) = explode(':',$perm); + + if (empty($group)) return false; + if (empty($key[$group])) $key[$group] = md5($group.$person_id); + + if (empty($access[$key[$group]])&&!empty($person_id)) { + $rs = aql::select(" {$group} { id, access_group } ", array( + 'where' => array(0=>(($group!='person')?'person_':'').'id='.$person_id), + 'limit' => 1 )); + $access[$key[$group]] = array_map(function($str) { + return md5(trim(strtolower($str))); + }, explode(',', $rs[0]['access_group'])); + // un-comment to see access array +// echo "
md5:\n".print_r($access,true)."
"; + } + + if ($granted=='*') return true; + + if (is_array($access[$key[$group]])) { + if (in_array(md5($granted), $access[$key[$group]])) { + return true; + } + } + } + return false; + } +} From 58953ffdeb5cffc625a89fee53fa792d33c384de Mon Sep 17 00:00:00 2001 From: System Administrator Date: Wed, 6 Jul 2016 11:12:43 -0400 Subject: [PATCH 03/18] auth class correction to functions.inc --- lib/core/functions.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core/functions.inc.php b/lib/core/functions.inc.php index 18ca93f..f120d93 100755 --- a/lib/core/functions.inc.php +++ b/lib/core/functions.inc.php @@ -1946,12 +1946,13 @@ public static function permission($params=null, $person_id=null) { // new method $perms = explode(';',$params); foreach($perms as $perm){ - list($group, $granted) = explode(':',$perm); + list($group, $granted) = explode(':',trim($perm)); if (empty($group)) return false; if (empty($key[$group])) $key[$group] = md5($group.$person_id); if (empty($access[$key[$group]])&&!empty($person_id)) { + $rs = aql::select(" {$group} { id, access_group } ", array( 'where' => array(0=>(($group!='person')?'person_':'').'id='.$person_id), 'limit' => 1 )); From b828bd8bb6412a9fb145824a21cb6a871248e433 Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Thu, 28 Jul 2016 15:31:44 -0400 Subject: [PATCH 04/18] added trim() to aql insert and update methods --- lib/class/class.Model.php | 37 +++++++++++++++++++++++++++++++++++++ lib/class/class.aql.php | 23 ++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 7422ca7..37a8d59 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -324,6 +324,8 @@ final public function __construct($data = null, $aql = null, $force_db = false, list($aql, $force_db, $cnf) = $this->mapConstructArgs($aql, $force_db, $cnf); # initialize this model + $r = new ReflectionClass($this); + $this->_model_path = dirname($r->getFilename()); $this->_model_name = get_class($this); $this->getModelAql($aql)->makeProperties(); @@ -338,6 +340,41 @@ final public function __construct($data = null, $aql = null, $force_db = false, $this->checkConstructorData($data, $force_db); } + /** + * returns sql query results + * + * @param array $a id array of ids to return records on + * + */ + public function getRecords($a) { + $aql_array = null; + if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ + $set_joins = ((isset($a['joins']))?false:true); + $set_columns = ((isset($a['columns']))?false:true); + + $a['primary_id'] = $this->_primary_table.'.id'; + $a['columns'][] = $this->_primary_table.".id as ".$this->_primary_table."_id"; + + $aql = file_get_contents($this->_model_path.'/'.$this->_model_name.'.aql'); + $aql_array = aql2array($aql); + + foreach($aql_array as $table => $array){ + if($set_joins){ + if(isset($array['on'])){ + $a['joins'][] = "LEFT JOIN ".$array['table'].(($array['table']!=$table)?' '.$table:'')." ON ".$array['on']; + } + } + if($set_columns){ + foreach($array['fields'] as $key => $link){ + $a['columns'][] = $link." as ".(($key=='id')?$array['table']."_":'').$key; + } + } + } + } + $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); + $results = sql($sql); + return $results; + } /** * checks for a proper identifier, loads object if set runs construct() diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index f3b2778..b40ed34 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -485,8 +485,9 @@ public static function insert($table, $fields, $silent = false) unset($fields['id']); foreach ($fields as $k => $v) { if ($v === null || $v === '') { - unset($fields[$k]); + unset($fields[$k]); continue; } + $fields[$k] = trim($v); } if (!$fields) { @@ -663,6 +664,8 @@ public function update($table, $fields, $identifier, $silent = false) return false; } + foreach ($fields as $k => $v) { $fields[$k] = trim($v); } + $dbw = self::getMasterDB(); $result = $dbw->AutoExecute($table, $fields, 'UPDATE', 'id = ' . $id); if ($result === true) { @@ -1068,7 +1071,9 @@ private static function sql_result($arr, $settings, $db_conn = null) $select_type = ($settings['select_type']) ?: 'sql'; $rs = array(); + $microtime_start = microtime(true); $r = $db_conn->Execute($arr[$select_type]); + hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); if ($r === false) { @@ -1142,8 +1147,14 @@ private static function sql_result($arr, $settings, $db_conn = null) ); if ($query) { + // new getRecords method + /* $ca = $s['constructor argument']; $p = new $m(); + $arr = array('ids'=>array_map(function($a) use ($ca) { return $a[$ca]; },$query)); + foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; } +*/ // old query loop method foreach ($query as $row) { $arg = $row[$s['constructor argument']]; + echo "
".$object.": ".print_r(Model::get($m, $arg, $sub_do_set),true)."
"; $o = Model::get($m, $arg, $sub_do_set); $tmp[$k][] = ($object) ? $o : $o->dataToArray(); } @@ -1157,7 +1168,17 @@ private static function sql_result($arr, $settings, $db_conn = null) } } } + // I have a query: + +$query = array('0'=>array('c1'=>'some value 1','c2'=>'some value 2'), + '1'=>array('c1'=>'some value 3','c2'=>'some value 4')); + + // and i just want 'c1' values returned to an array. +$ca = 'c1'; +$c1 = array_map(function($a) use ($ca) { return $a[$ca]; },$query) + // $c1 equals: + array('some value 1', 'some value 3'); if ($object && $aql_statement) { $tmp_model = ($object === true) From 763a9751ce7cf3c1041a70a60f4504abc8f3a51d Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Thu, 28 Jul 2016 15:33:39 -0400 Subject: [PATCH 05/18] added trim() to aql insert and update methods --- lib/class/class.Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 37a8d59..6fbddb6 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -343,10 +343,10 @@ final public function __construct($data = null, $aql = null, $force_db = false, /** * returns sql query results * - * @param array $a id array of ids to return records on + * @param array $a array of ids to return records on * */ - public function getRecords($a) { +/* public function getRecords($a) { $aql_array = null; if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ $set_joins = ((isset($a['joins']))?false:true); @@ -374,7 +374,7 @@ public function getRecords($a) { $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); $results = sql($sql); return $results; - } + }*/ /** * checks for a proper identifier, loads object if set runs construct() From 68d61b629da57e8fea8fb23df883519a8ab8ae48 Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Thu, 28 Jul 2016 15:41:15 -0400 Subject: [PATCH 06/18] added trim() to aql insert and update methods --- lib/class/class.Model.php | 37 +++++++++++++++++++++++++++++++++++++ lib/class/class.aql.php | 16 +++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 7422ca7..90dcd74 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -324,6 +324,8 @@ final public function __construct($data = null, $aql = null, $force_db = false, list($aql, $force_db, $cnf) = $this->mapConstructArgs($aql, $force_db, $cnf); # initialize this model + $r = new ReflectionClass($this); + $this->_model_path = dirname($r->getFilename()); $this->_model_name = get_class($this); $this->getModelAql($aql)->makeProperties(); @@ -338,6 +340,41 @@ final public function __construct($data = null, $aql = null, $force_db = false, $this->checkConstructorData($data, $force_db); } + /** + * returns sql query results + * + * @param array $a array of ids to return records on + * + */ + public function getRecords($a) { + $aql_array = null; + if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ + $set_joins = ((isset($a['joins']))?false:true); + $set_columns = ((isset($a['columns']))?false:true); + + $a['primary_id'] = $this->_primary_table.'.id'; + $a['columns'][] = $this->_primary_table.".id as ".$this->_primary_table."_id"; + + $aql = file_get_contents($this->_model_path.'/'.$this->_model_name.'.aql'); + $aql_array = aql2array($aql); + + foreach($aql_array as $table => $array){ + if($set_joins){ + if(isset($array['on'])){ + $a['joins'][] = "LEFT JOIN ".$array['table'].(($array['table']!=$table)?' '.$table:'')." ON ".$array['on']; + } + } + if($set_columns){ + foreach($array['fields'] as $key => $link){ + $a['columns'][] = $link." as ".(($key=='id')?$array['table']."_":'').$key; + } + } + } + } + $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); + $results = sql($sql); + return $results; + } /** * checks for a proper identifier, loads object if set runs construct() diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index f3b2778..3663609 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -485,8 +485,9 @@ public static function insert($table, $fields, $silent = false) unset($fields['id']); foreach ($fields as $k => $v) { if ($v === null || $v === '') { - unset($fields[$k]); + unset($fields[$k]); continue; } + $fields[$k] = trim($v); } if (!$fields) { @@ -663,6 +664,8 @@ public function update($table, $fields, $identifier, $silent = false) return false; } + foreach ($fields as $k => $v) { $fields[$k] = trim($v); } + $dbw = self::getMasterDB(); $result = $dbw->AutoExecute($table, $fields, 'UPDATE', 'id = ' . $id); if ($result === true) { @@ -1068,7 +1071,9 @@ private static function sql_result($arr, $settings, $db_conn = null) $select_type = ($settings['select_type']) ?: 'sql'; $rs = array(); + $microtime_start = microtime(true); $r = $db_conn->Execute($arr[$select_type]); + hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); if ($r === false) { @@ -1142,11 +1147,16 @@ private static function sql_result($arr, $settings, $db_conn = null) ); if ($query) { - foreach ($query as $row) { + // new getRecords method + $ca = $s['constructor argument']; $p = new $m(); + $arr = array('ids'=>array_map(function($a) use ($ca) { return $a[$ca]; },$query)); + foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; } + // old query loop method +/* foreach ($query as $row) { $arg = $row[$s['constructor argument']]; $o = Model::get($m, $arg, $sub_do_set); $tmp[$k][] = ($object) ? $o : $o->dataToArray(); - } + }*/ } } else if (!$s['plural']) { $arg = (int) $tmp[$s['constructor argument']]; From 2c38290313accec9623925b1ddfee8cc13771cb3 Mon Sep 17 00:00:00 2001 From: TerenceOB Date: Thu, 28 Jul 2016 15:42:02 -0400 Subject: [PATCH 07/18] ignore files (reverted from commit 7df42c63e3bcdf7c4a697280a849b280d4149997) --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2eabe5f..619e492 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ *# .#* *.DS_Store -/.gitignore -/version.txt From 925a829304b8d96af193475d5e0cebb83e5e3616 Mon Sep 17 00:00:00 2001 From: TerenceOB Date: Thu, 28 Jul 2016 15:47:48 -0400 Subject: [PATCH 08/18] Merge remote-tracking branch 'origin/master' (reverted from commit fabf6e3dbc5ae1fb44c4fdc187d64651ceaa04c8) --- lib/class/class.Model.php | 37 ------------------------------------- lib/class/class.aql.php | 23 +---------------------- 2 files changed, 1 insertion(+), 59 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 6fbddb6..7422ca7 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -324,8 +324,6 @@ final public function __construct($data = null, $aql = null, $force_db = false, list($aql, $force_db, $cnf) = $this->mapConstructArgs($aql, $force_db, $cnf); # initialize this model - $r = new ReflectionClass($this); - $this->_model_path = dirname($r->getFilename()); $this->_model_name = get_class($this); $this->getModelAql($aql)->makeProperties(); @@ -340,41 +338,6 @@ final public function __construct($data = null, $aql = null, $force_db = false, $this->checkConstructorData($data, $force_db); } - /** - * returns sql query results - * - * @param array $a array of ids to return records on - * - */ -/* public function getRecords($a) { - $aql_array = null; - if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ - $set_joins = ((isset($a['joins']))?false:true); - $set_columns = ((isset($a['columns']))?false:true); - - $a['primary_id'] = $this->_primary_table.'.id'; - $a['columns'][] = $this->_primary_table.".id as ".$this->_primary_table."_id"; - - $aql = file_get_contents($this->_model_path.'/'.$this->_model_name.'.aql'); - $aql_array = aql2array($aql); - - foreach($aql_array as $table => $array){ - if($set_joins){ - if(isset($array['on'])){ - $a['joins'][] = "LEFT JOIN ".$array['table'].(($array['table']!=$table)?' '.$table:'')." ON ".$array['on']; - } - } - if($set_columns){ - foreach($array['fields'] as $key => $link){ - $a['columns'][] = $link." as ".(($key=='id')?$array['table']."_":'').$key; - } - } - } - } - $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); - $results = sql($sql); - return $results; - }*/ /** * checks for a proper identifier, loads object if set runs construct() diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index b40ed34..f3b2778 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -485,9 +485,8 @@ public static function insert($table, $fields, $silent = false) unset($fields['id']); foreach ($fields as $k => $v) { if ($v === null || $v === '') { - unset($fields[$k]); continue; + unset($fields[$k]); } - $fields[$k] = trim($v); } if (!$fields) { @@ -664,8 +663,6 @@ public function update($table, $fields, $identifier, $silent = false) return false; } - foreach ($fields as $k => $v) { $fields[$k] = trim($v); } - $dbw = self::getMasterDB(); $result = $dbw->AutoExecute($table, $fields, 'UPDATE', 'id = ' . $id); if ($result === true) { @@ -1071,9 +1068,7 @@ private static function sql_result($arr, $settings, $db_conn = null) $select_type = ($settings['select_type']) ?: 'sql'; $rs = array(); - $microtime_start = microtime(true); $r = $db_conn->Execute($arr[$select_type]); - hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); if ($r === false) { @@ -1147,14 +1142,8 @@ private static function sql_result($arr, $settings, $db_conn = null) ); if ($query) { - // new getRecords method - /* $ca = $s['constructor argument']; $p = new $m(); - $arr = array('ids'=>array_map(function($a) use ($ca) { return $a[$ca]; },$query)); - foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; } -*/ // old query loop method foreach ($query as $row) { $arg = $row[$s['constructor argument']]; - echo "
".$object.": ".print_r(Model::get($m, $arg, $sub_do_set),true)."
"; $o = Model::get($m, $arg, $sub_do_set); $tmp[$k][] = ($object) ? $o : $o->dataToArray(); } @@ -1168,17 +1157,7 @@ private static function sql_result($arr, $settings, $db_conn = null) } } } - // I have a query: - -$query = array('0'=>array('c1'=>'some value 1','c2'=>'some value 2'), - '1'=>array('c1'=>'some value 3','c2'=>'some value 4')); - - // and i just want 'c1' values returned to an array. -$ca = 'c1'; -$c1 = array_map(function($a) use ($ca) { return $a[$ca]; },$query) - // $c1 equals: - array('some value 1', 'some value 3'); if ($object && $aql_statement) { $tmp_model = ($object === true) From bb3ca892d3b78788c1ff7cd150109b6cad17a382 Mon Sep 17 00:00:00 2001 From: TerenceOB Date: Thu, 28 Jul 2016 15:54:06 -0400 Subject: [PATCH 09/18] auth class correction to functions.inc (reverted from commit 58953ffdeb5cffc625a89fee53fa792d33c384de) --- lib/core/functions.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/core/functions.inc.php b/lib/core/functions.inc.php index f120d93..18ca93f 100755 --- a/lib/core/functions.inc.php +++ b/lib/core/functions.inc.php @@ -1946,13 +1946,12 @@ public static function permission($params=null, $person_id=null) { // new method $perms = explode(';',$params); foreach($perms as $perm){ - list($group, $granted) = explode(':',trim($perm)); + list($group, $granted) = explode(':',$perm); if (empty($group)) return false; if (empty($key[$group])) $key[$group] = md5($group.$person_id); if (empty($access[$key[$group]])&&!empty($person_id)) { - $rs = aql::select(" {$group} { id, access_group } ", array( 'where' => array(0=>(($group!='person')?'person_':'').'id='.$person_id), 'limit' => 1 )); From 680bbf30db2540d09303957d1fa433c87c4d1386 Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Thu, 28 Jul 2016 16:02:49 -0400 Subject: [PATCH 10/18] added trim() to aql insert and update methods --- lib/class/class.Model.php | 37 +++++++++++++++++++++++++++++++++++++ lib/class/class.aql.php | 14 ++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 7422ca7..6fbddb6 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -324,6 +324,8 @@ final public function __construct($data = null, $aql = null, $force_db = false, list($aql, $force_db, $cnf) = $this->mapConstructArgs($aql, $force_db, $cnf); # initialize this model + $r = new ReflectionClass($this); + $this->_model_path = dirname($r->getFilename()); $this->_model_name = get_class($this); $this->getModelAql($aql)->makeProperties(); @@ -338,6 +340,41 @@ final public function __construct($data = null, $aql = null, $force_db = false, $this->checkConstructorData($data, $force_db); } + /** + * returns sql query results + * + * @param array $a array of ids to return records on + * + */ +/* public function getRecords($a) { + $aql_array = null; + if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ + $set_joins = ((isset($a['joins']))?false:true); + $set_columns = ((isset($a['columns']))?false:true); + + $a['primary_id'] = $this->_primary_table.'.id'; + $a['columns'][] = $this->_primary_table.".id as ".$this->_primary_table."_id"; + + $aql = file_get_contents($this->_model_path.'/'.$this->_model_name.'.aql'); + $aql_array = aql2array($aql); + + foreach($aql_array as $table => $array){ + if($set_joins){ + if(isset($array['on'])){ + $a['joins'][] = "LEFT JOIN ".$array['table'].(($array['table']!=$table)?' '.$table:'')." ON ".$array['on']; + } + } + if($set_columns){ + foreach($array['fields'] as $key => $link){ + $a['columns'][] = $link." as ".(($key=='id')?$array['table']."_":'').$key; + } + } + } + } + $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); + $results = sql($sql); + return $results; + }*/ /** * checks for a proper identifier, loads object if set runs construct() diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index f04cc06..4f17a1b 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -485,8 +485,9 @@ public static function insert($table, $fields, $silent = false) unset($fields['id']); foreach ($fields as $k => $v) { if ($v === null || $v === '') { - unset($fields[$k]); + unset($fields[$k]); continue; } + $fields[$k] = trim($v); } if (!$fields) { @@ -663,6 +664,8 @@ public function update($table, $fields, $identifier, $silent = false) return false; } + foreach ($fields as $k => $v) { $fields[$k] = trim($v); } + $dbw = self::getMasterDB(); $result = $dbw->AutoExecute($table, $fields, 'UPDATE', 'id = ' . $id); if ($result === true) { @@ -1068,7 +1071,9 @@ private static function sql_result($arr, $settings, $db_conn = null) $select_type = ($settings['select_type']) ?: 'sql'; $rs = array(); + $microtime_start = microtime(true); $r = $db_conn->Execute($arr[$select_type]); + hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); if ($r === false) { @@ -1142,11 +1147,16 @@ private static function sql_result($arr, $settings, $db_conn = null) ); if ($query) { + // new getRecords method +/* $ca = $s['constructor argument']; $p = new $m(); + $arr = array('ids'=>array_map(function($a) use ($ca) { return $a[$ca]; },$query)); + foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; }*/ + // old query loop method foreach ($query as $row) { $arg = $row[$s['constructor argument']]; $o = Model::get($m, $arg, $sub_do_set); $tmp[$k][] = ($object) ? $o : $o->dataToArray(); - }*/ + } } } else if (!$s['plural']) { $arg = (int) $tmp[$s['constructor argument']]; From 8ce8c1d05337f19ac6af712b28d2b344e00f4e68 Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Fri, 12 Aug 2016 10:48:41 -0400 Subject: [PATCH 11/18] re-enabled getRecords method --- lib/class/class.Model.php | 4 ++-- lib/class/class.aql.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 6fbddb6..90dcd74 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -346,7 +346,7 @@ final public function __construct($data = null, $aql = null, $force_db = false, * @param array $a array of ids to return records on * */ -/* public function getRecords($a) { + public function getRecords($a) { $aql_array = null; if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ $set_joins = ((isset($a['joins']))?false:true); @@ -374,7 +374,7 @@ final public function __construct($data = null, $aql = null, $force_db = false, $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); $results = sql($sql); return $results; - }*/ + } /** * checks for a proper identifier, loads object if set runs construct() diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index 4f17a1b..fb0cf95 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -1148,15 +1148,15 @@ private static function sql_result($arr, $settings, $db_conn = null) if ($query) { // new getRecords method -/* $ca = $s['constructor argument']; $p = new $m(); + $ca = $s['constructor argument']; $p = new $m(); $arr = array('ids'=>array_map(function($a) use ($ca) { return $a[$ca]; },$query)); - foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; }*/ + foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; } // old query loop method - foreach ($query as $row) { +/* foreach ($query as $row) { $arg = $row[$s['constructor argument']]; $o = Model::get($m, $arg, $sub_do_set); $tmp[$k][] = ($object) ? $o : $o->dataToArray(); - } + }*/ } } else if (!$s['plural']) { $arg = (int) $tmp[$s['constructor argument']]; From eb06c0dd3669e1e7998e16ed230bd4d00e1d99a3 Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Mon, 15 Aug 2016 10:50:23 -0400 Subject: [PATCH 12/18] check to make sure class exists before executing --- lib/class/class.aql.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index fb0cf95..1c610b2 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -1073,7 +1073,9 @@ private static function sql_result($arr, $settings, $db_conn = null) $rs = array(); $microtime_start = microtime(true); $r = $db_conn->Execute($arr[$select_type]); - hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); + if(class_exists('hwc_debug')){ + hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); + } if ($r === false) { From 2c426efeab14bdfd4aee0422eb2111fcd3c16e3f Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Mon, 15 Aug 2016 15:48:59 -0400 Subject: [PATCH 13/18] new enhanced aql with trim and getRecords method --- lib/class/class.Model.php | 4 ++-- lib/class/class.aql.php | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 6fbddb6..90dcd74 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -346,7 +346,7 @@ final public function __construct($data = null, $aql = null, $force_db = false, * @param array $a array of ids to return records on * */ -/* public function getRecords($a) { + public function getRecords($a) { $aql_array = null; if(file_exists($this->_model_path.'/'.$this->_model_name.'.aql')){ $set_joins = ((isset($a['joins']))?false:true); @@ -374,7 +374,7 @@ final public function __construct($data = null, $aql = null, $force_db = false, $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); $results = sql($sql); return $results; - }*/ + } /** * checks for a proper identifier, loads object if set runs construct() diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index 4f17a1b..1c610b2 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -1073,7 +1073,9 @@ private static function sql_result($arr, $settings, $db_conn = null) $rs = array(); $microtime_start = microtime(true); $r = $db_conn->Execute($arr[$select_type]); - hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); + if(class_exists('hwc_debug')){ + hwc_debug::add_aql($arr[$select_type], number_format(microtime(true) - $microtime_start,3)); + } if ($r === false) { @@ -1148,15 +1150,15 @@ private static function sql_result($arr, $settings, $db_conn = null) if ($query) { // new getRecords method -/* $ca = $s['constructor argument']; $p = new $m(); + $ca = $s['constructor argument']; $p = new $m(); $arr = array('ids'=>array_map(function($a) use ($ca) { return $a[$ca]; },$query)); - foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; }*/ + foreach($p->getRecords($arr) as $row){ $tmp[$k][]['_data'] = $row; } // old query loop method - foreach ($query as $row) { +/* foreach ($query as $row) { $arg = $row[$s['constructor argument']]; $o = Model::get($m, $arg, $sub_do_set); $tmp[$k][] = ($object) ? $o : $o->dataToArray(); - } + }*/ } } else if (!$s['plural']) { $arg = (int) $tmp[$s['constructor argument']]; From a6c8039298d34a25a9ee6f0958bc44799d8c364c Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Tue, 23 Aug 2016 11:11:43 -0400 Subject: [PATCH 14/18] adjustment to sql return and added ide --- lib/class/class.Model.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index 90dcd74..ac74202 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -371,8 +371,9 @@ public function getRecords($a) { } } } - $sql = "SELECT ".join(",",$a['columns'])." FROM ".$this->_primary_table." ".join(" ",$a['joins'])." WHERE ".$a['primary_id']." IN ('".join("','",$a['ids'])."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".join("','",$a['ids'])."')"); - $results = sql($sql); + $sql = "SELECT ".((!empty($a['columns']))?join(",",$a['columns']):'*')." FROM ".$this->_primary_table." ".((!empty($a['joins']))?join(" ",$a['joins']):'')." WHERE ".$a['primary_id']." IN ('".((!empty($a['ids']))?join("','",$a['ids']):'')."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".((!empty($a['ids']))?join("','",$a['ids']):'')."')"); + $results = sql_array($sql); + foreach($results as $k=>$r){ $results[$k][$this->_primary_table.'_ide'] = encrypt($r[$this->_primary_table.'_id'],$this->_primary_table); } return $results; } From 26b81a779ea4c86dd35d04e2df0ac23b6fc2633d Mon Sep 17 00:00:00 2001 From: HarleyHWC Date: Wed, 26 Oct 2016 09:58:02 -0400 Subject: [PATCH 15/18] modifications for new grid class and data handling --- lib/class/class.Model.php | 25 +++++++++++++++++++++---- lib/class/class.aql.php | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/class/class.Model.php b/lib/class/class.Model.php index ac74202..3eb05d7 100755 --- a/lib/class/class.Model.php +++ b/lib/class/class.Model.php @@ -328,6 +328,7 @@ final public function __construct($data = null, $aql = null, $force_db = false, $this->_model_path = dirname($r->getFilename()); $this->_model_name = get_class($this); $this->getModelAql($aql)->makeProperties(); + //$this->_token = $this->getToken(); # set if we're refreshing it $this->_force_db = ($force_db || $_GET['refresh']); @@ -357,23 +358,39 @@ public function getRecords($a) { $aql = file_get_contents($this->_model_path.'/'.$this->_model_name.'.aql'); $aql_array = aql2array($aql); - + $tables = null; $ta = 'table'; +//echo "
".print_r($aql_array,true)."
"; foreach($aql_array as $table => $array){ if($set_joins){ if(isset($array['on'])){ $a['joins'][] = "LEFT JOIN ".$array['table'].(($array['table']!=$table)?' '.$table:'')." ON ".$array['on']; + $ta = ((isset($array['as']))?'as':'table'); + $a['columns'][] = $array[$ta].".id as ".$array[$ta]."_id"; + $tables[] = $array[$ta]; } } if($set_columns){ foreach($array['fields'] as $key => $link){ - $a['columns'][] = $link." as ".(($key=='id')?$array['table']."_":'').$key; + if($this->_primary_table."_id"==$key) continue; + $a['columns'][] = $link." as ".(($key=='id')?$array[$ta]."_":'').$key; } } } } $sql = "SELECT ".((!empty($a['columns']))?join(",",$a['columns']):'*')." FROM ".$this->_primary_table." ".((!empty($a['joins']))?join(" ",$a['joins']):'')." WHERE ".$a['primary_id']." IN ('".((!empty($a['ids']))?join("','",$a['ids']):'')."')".((isset($a['order_by']))?' ORDER BY '.$a['order_by']:" ORDER BY FIELD(".$a['primary_id'].", '".((!empty($a['ids']))?join("','",$a['ids']):'')."')"); + //echo $sql; $results = sql_array($sql); - foreach($results as $k=>$r){ $results[$k][$this->_primary_table.'_ide'] = encrypt($r[$this->_primary_table.'_id'],$this->_primary_table); } + //echo "
".print_r($results, true)."
"; + foreach($results as $k=>$r){ + //$results[$k][$this->_primary_table.'_id'] = $r[$this->_primary_table.'_id']; + $results[$k][$this->_primary_table.'_ide'] = encrypt($r[$this->_primary_table.'_id'],$this->_primary_table); + if(isset($tables)){ + foreach($tables as $table){ + $results[$k][$table.'_ide'] = encrypt($results[$k][$table.'_id'],$table); + } + } + } +// echo "
".print_r($results, true)."
"; return $results; } @@ -1552,7 +1569,7 @@ public function getToken($id = null, $primary_table = null) $id = decrypt($id, $primary_table); } $id = ($id) ?: $this->getID(); - +//echo "
".print_r(array($primary_table,$id, self::_makeToken($id, $primary_table)),true)."
"; return self::_makeToken($id, $primary_table); } diff --git a/lib/class/class.aql.php b/lib/class/class.aql.php index 1c610b2..20e9bb9 100755 --- a/lib/class/class.aql.php +++ b/lib/class/class.aql.php @@ -664,7 +664,7 @@ public function update($table, $fields, $identifier, $silent = false) return false; } - foreach ($fields as $k => $v) { $fields[$k] = trim($v); } + foreach ($fields as $k => $v) { $fields[$k] = trim($v); } //($v=='-0001-11-30'?NULL:trim($v)); } $dbw = self::getMasterDB(); $result = $dbw->AutoExecute($table, $fields, 'UPDATE', 'id = ' . $id); From 9967f9c26397ba85d8d188321920f888dd6b19ea Mon Sep 17 00:00:00 2001 From: TerenceOB Date: Fri, 28 Oct 2016 11:15:08 -0400 Subject: [PATCH 16/18] Add Construct --- lib/Sky/Memcache/Transaction/Type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sky/Memcache/Transaction/Type.php b/lib/Sky/Memcache/Transaction/Type.php index d0032a9..b655284 100755 --- a/lib/Sky/Memcache/Transaction/Type.php +++ b/lib/Sky/Memcache/Transaction/Type.php @@ -42,7 +42,7 @@ abstract class Type /** * Abstract constructor, child class should */ - abstract public function __construct(); + abstract public function __construct($key, $value, $duration = null); /** * Type should be either set | delete From 5af5db95f4df81db45d30f23575fb1cc5fdb9e92 Mon Sep 17 00:00:00 2001 From: val19116 Date: Tue, 20 Dec 2016 12:45:18 -0500 Subject: [PATCH 17/18] 1120 - Added video type mp4, mpeg to function getMimeTypes() --- lib/core/functions.inc.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/core/functions.inc.php b/lib/core/functions.inc.php index 18ca93f..d3d7f19 100755 --- a/lib/core/functions.inc.php +++ b/lib/core/functions.inc.php @@ -1886,17 +1886,21 @@ function getMimeTypes() 'class' => 'application/java-vm', 'jar' => 'application/java-archive', - // multimedia - 'mp3' => 'audio/mpeg', - 'wav' => 'audio/vnd.wav', - 'oga' => 'audio/vorbis', - 'ogv' => 'video/ogg', - 'ogg' => 'video/ogg', - 'webm' => 'video/webm', + // audio + 'mp3' => 'audio/mpeg', + 'wav' => 'audio/vnd.wav', + 'oga' => 'audio/vorbis', + + // video + 'ogv' => 'video/ogg', + 'ogg' => 'video/ogg', + 'webm' => 'video/webm', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'swf' => 'application/x-shockwave-flash', + 'mp4' => 'video/mp4', + 'mpg' => 'video/mpeg', // adobe From ea7417f12ef47a123385feea97ab674607707bf5 Mon Sep 17 00:00:00 2001 From: Priti Rawat Date: Thu, 10 Jan 2019 23:40:47 +0530 Subject: [PATCH 18/18] make changes on viewport of html5 file for responsive design --- templates/html5/html5.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/html5/html5.php b/templates/html5/html5.php index bf506a2..0f8d3c9 100755 --- a/templates/html5/html5.php +++ b/templates/html5/html5.php @@ -26,7 +26,7 @@ <?=$this->title?> - + seoMetaContent();