Exemple #1
0
 public static function search($allArgs, $con)
 {
     $terms = array();
     $class = get_called_class();
     $pre = strtolower($class) . "_";
     $objProps = $class::$classProps["objProps"];
     $fkeys = explode(",", $class::$classProps["fkeys"]);
     $tableCols = dbObject::getCols($class);
     foreach ($objProps as $objProp) {
         if (in_array($objProp, $fkeys)) {
             $col = $objProp;
         } else {
             $col = strtolower($class) . "_" . $objProp;
         }
         if (dbObject::propInArgs($col, $allArgs)) {
             $term = Member::makeSearchTerm($col, $allArgs);
             if ($term != false) {
                 $terms[] = $term;
             }
         }
     }
     $sql = "SELECT * FROM `" . Member::$classProps["tableName"] . "`";
     $i = 0;
     foreach ($terms as $term) {
         if ($i == 0) {
             $i = 1;
             $sql .= " WHERE ";
         } else {
             $sql .= " AND ";
         }
         $sql .= $term[0];
         if ($term[3] == true) {
             if ($term[1] != "") {
                 $sql .= ">=\"" . $term[1] . "\"";
             }
             if ($term[2] != "") {
                 if ($term[1] != "") {
                     $sql .= " AND ";
                 }
                 $sql .= $term[0] . "<=\"" . $term[2] . "\"";
             }
         } else {
             $sql .= "=\"" . $term[1] . "\"";
         }
     }
     if ($result = mysqli_query($con, $sql)) {
         return $result;
     } else {
         return false;
     }
 }
 /**
 	The awesome find function. Creates a QueryBuilder Object wich creates a Query to find all objects for your filters.
 * <code>
 * //  Syntax for the filters array: 
 * Array(
  	 *		'ID > 500', // just a key element, it will detect this, map the fields and just execute it.
 *		'property'=> 'value' // $property of $classname has to be $value 
 *		Array('ClassName'=> array('property'=>'value')// Filter by a (relational) class's property. You can use this recursively!!
 * ) 
 * </code>
  	 * @param string $className Classname to find (has to be a relation of $this or get_class($this))
 * @param array $filters array of filters to use in query
 * @param array $extra array of eventual order by / group by parameters
 * @param array $justThese Fetch only these fields from the table. Useful if you don't want to fetch large text or blob columns.
 * @uses QueryBuilder to build the actual query
 * @returns array a batch of pre-filled objects of $className or false if it finds nothing
 */
 public function Find($className, $filters = array(), $extra = array(), $justThese = array())
 {
     $originalClassName = $className instanceof dbObject ? get_class($className) : $className;
     $class = new $originalClassName();
     if ($originalClassName != get_class($this) && $this->ID != false) {
         $filters["ID"] = $this->ID;
         $filters = array(get_class($this) => $filters);
     }
     $builder = new QueryBuilder($originalClassName, $filters, $extra, $justThese);
     $input = dbConnection::getInstance($this->databaseInfo->connection)->fetchAll($builder->buildQuery(), 'assoc');
     return dbObject::importArray($originalClassName, $input);
 }
<?php

error_reporting(E_ALL | E_STRICT);
require_once "../MysqliDb.php";
require_once "../dbObject.php";
$db = new Mysqlidb('localhost', 'root', '', 'testdb');
dbObject::autoload("models");
$tables = array('users' => array('login' => 'char(10) not null', 'active' => 'bool default 0', 'customerId' => 'int(10) not null', 'firstName' => 'char(10) not null', 'lastName' => 'char(10)', 'password' => 'text not null', 'createdAt' => 'datetime', 'updatedAt' => 'datetime', 'expires' => 'datetime', 'loginCount' => 'int(10) default 0'), 'products' => array('customerId' => 'int(10) not null', 'userId' => 'int(10) not null', 'productName' => 'char(50)'));
$data = array('user' => array(array('login' => 'user1', 'customerId' => 10, 'firstName' => 'John', 'lastName' => 'Doe', 'password' => $db->func('SHA1(?)', array("secretpassword+salt")), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc()), array('login' => 'user2', 'customerId' => 10, 'firstName' => 'Mike', 'lastName' => NULL, 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(2)), array('login' => 'user3', 'active' => true, 'customerId' => 11, 'firstName' => 'Pete', 'lastName' => 'D', 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(3))), 'product' => array(array('customerId' => 1, 'userId' => 1, 'productName' => 'product1'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product2'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product3'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product4'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product5')));
function createTable($name, $data)
{
    global $db;
    //$q = "CREATE TABLE $name (id INT(9) UNSIGNED PRIMARY KEY NOT NULL";
    $q = "CREATE TABLE {$name} (id INT(9) UNSIGNED PRIMARY KEY AUTO_INCREMENT";
    foreach ($data as $k => $v) {
        $q .= ", {$k} {$v}";
    }
    $q .= ")";
    $db->rawQuery($q);
}
// rawQuery test
foreach ($tables as $name => $fields) {
    $db->rawQuery("DROP TABLE " . $name);
    createTable($name, $fields);
}
foreach ($data as $name => $datas) {
    foreach ($data[$name] as $userData) {
        $obj = new $name($userData);
        $id = $obj->save();
        if ($obj->errors) {
            echo "errors:";
Exemple #4
0
 /**
  * Pagination wraper to get()
  *
  * @access public
  * @param int $page Page number
  * @param array|string $fields Array or coma separated list of fields to fetch
  * @return array
  */
 private function paginate($page, $fields = null)
 {
     $this->db->pageLimit = self::$pageLimit;
     $res = $this->db->paginate($this->dbTable, $page, $fields);
     self::$totalPages = $this->db->totalPages;
     return $res;
 }
?>
</th>
        <th><?php 
echo gettext('Inactive Date');
?>
</th>
       </tr>
      </thead>
      <tbody class="form_data_line_tbody">
       <?php 
$count = 0;
foreach ($hr_approval_limit_line_object as $hr_approval_limit_line) {
    if (!empty(${$class_second}->limit_object)) {
        $appr_obj = hr_approval_object::find_by_keyColumn(${$class_second}->limit_object);
        $appr_obj_val = $appr_obj->object_value;
        $value_result = $appr_obj->value_type == 'DYNAMIC' ? dbObject::find_by_sql_array($appr_obj_val) : null;
        //                pa($value_result);
    }
    ?>
         
        <tr class="hr_approval_limit_line<?php 
    echo $count;
    ?>
">
         <td><?php 
    echo ino_inline_action(${$class_second}->hr_approval_limit_line_id, array('hr_payroll_id' => $hr_approval_limit_header->hr_approval_limit_header_id));
    ?>
    
         </td>
         <td><?php 
    $f->text_field_wid2sr('hr_approval_limit_line_id');
Exemple #6
0
$sount = 0;
$i = 0;
$Error = '';
$neworderarray['0'] = "";
$neworderarray = array_merge($neworderarray, $_POST['neworder']);
unset($neworderarray['0']);
//loop through the list of ids and update your db
foreach ($neworderarray as $order => $id) {
    $data = array('sort' => $order);
    $db->where('id', $id);
    if ($db->update('sob', $data)) {
        $count++;
    } else {
        $Error = $Error . '' . $db->getLastError();
    }
    $i++;
}
if ($count != $i) {
    echo $Error;
} else {
    $sob = dbObject::table('sob')->get();
    $db->orderBy("sort", "asc");
    $sob = sob::get();
    foreach ($sob as $s) {
        $m[] = round($s->kef, 2);
    }
    echo '1-2 :' . round($m['0'] * $m['1'], 2) . '<br />';
    echo '3-4 :' . round($m['2'] * $m['3'], 2) . '<br />';
    echo '1-3 :' . round($m['0'] * $m['2'], 2) . '<br />';
    echo '2-3 :' . round($m['1'] * $m['2'], 2) . '<br />';
}
Exemple #7
0
 public function __call($closure, $arguments)
 {
     return parent::__call($closure, $arguments);
 }
Exemple #8
0
<?php

include_once "../../includes/basics/basics.inc";
?>
<link href="<?php 
echo HOME_URL;
?>
includes/ecss/getsvgimage.css" media="all" rel="stylesheet" type="text/css" />
<?php 
if (!empty($_GET['find_result'])) {
    if (!empty($_GET['query_v']) && !empty($_GET['chart_label']) && !empty($_GET['chart_value'])) {
        $svgimg = new getsvgimage();
        $result = $result1 = dbObject::find_by_sql($_GET['query_v']);
        $chart_label = str_replace('.', '__', $_GET['chart_label']);
        $chart_value = str_replace('.', '__', $_GET['chart_value']);
        $chart_name = !empty($_GET['chart_name']) ? $_GET['chart_name'] : 'Custom View Chart';
        $chart_width = !empty($_GET['chart_width']) ? $_GET['chart_width'] : '450';
        $chart_height = !empty($_GET['chart_height']) ? $_GET['chart_height'] : '450';
        $chart_type = !empty($_GET['chart_type']) ? $_GET['chart_type'] : 'clustered_column';
        $legend_name = !empty($_GET['chart_legend']) ? $_GET['chart_legend'] : '';
        $legend_name = str_replace('.', '__', $legend_name);
        //getSvgData($result, $legend_name, $chart_label, $chart_value, $legend, $labels, $data);
        $svgimg->setProperty('_chart_name', $chart_name);
        $svgimg->setProperty('_chart_width', $chart_width);
        $svgimg->setProperty('_chart_height', $chart_height);
        $svgimg->setProperty('_chart_type', $chart_type);
        $svgimg->result = $result;
        $svgimg->legend_name = $legend_name;
        $svgimg->chart_label = $chart_label;
        $svgimg->chart_value = $chart_value;
        $svg_chart = $svgimg->getSvgChart_forView();
Exemple #9
0
 /**
  * Run default constructor and define table name
  */
 function __construct()
 {
     parent::__construct();
     $this->table = 'list';
 }
 /**
  * Pagination wraper to get()
  *
  * @access public
  * @param int $page Page number
  * @param array|string $fields Array or coma separated list of fields to fetch
  * @return array
  */
 private function paginate($page, $fields = null)
 {
     $offset = self::$pageLimit * ($page - 1);
     $this->db->withTotalCount();
     $results = $this->get(array($offset, self::$pageLimit), $fields);
     self::$totalPages = round($this->db->totalCount / self::$pageLimit);
     return $results;
 }
 /**
  * Pagination wraper to get()
  *
  * @access public
  * @param int $page Page number
  * @param array|string $fields Array or coma separated list of fields to fetch
  * @return array
  */
 private function paginate($page, $fields = null)
 {
     $this->db->pageLimit = self::$pageLimit;
     $res = $this->db->paginate($this->dbTable, $page, $fields);
     self::$totalPages = $this->db->totalPages;
     if ($this->db->count == 0) {
         return null;
     }
     foreach ($res as &$r) {
         $this->processArrays($r);
         $this->data = $r;
         $this->processAllWith($r, false);
         if ($this->returnType == 'Object') {
             $item = new static($r);
             $item->isNew = false;
             $objects[] = $item;
         }
     }
     $this->_with = array();
     if ($this->returnType == 'Object') {
         return $objects;
     }
     if ($this->returnType == 'Json') {
         return json_encode($res);
     }
     return $res;
 }
Exemple #12
0
        $program_name = $_POST['program_name'][0];
        if (!empty($_POST['download_as_text'])) {
            $download_as_text = 1;
        } else {
            $download_as_text = 0;
        }
        ${$class} = new $class();
        $result = call_user_func(array(${$class}, $program_name), $_POST);
        $array_var = json_decode(json_encode($result), true);
        $download_format = !empty($_POST['download_format'][0]) ? $_POST['download_format'][0] : 'text_format';
    }
} else {
    $str_var = $_POST["data"];
    if (!empty($_POST['data_type']) && $_POST['data_type'] == 'sql_query') {
        $sql = unserialize(base64_decode($str_var));
        $array_var = json_decode(json_encode(dbObject::find_by_sql($sql)), true);
    } else {
        $array_var = unserialize(base64_decode($str_var));
    }
    if (!empty($_POST['download_format'])) {
        $download_format = is_array($_POST['download_format']) ? $_POST['download_format'][0] : 'text_format';
    } else {
        $download_format = 'text_format';
    }
}
switch ($download_format) {
    case 'excel_format':
        $format_extn = '.csv';
        break;
    case 'xml_format':
        $format_extn = '.txt';