public function find() { $result = array(); $where = 'where 1 = 1 '; foreach ($this->columns as $objCol => $dbCol) { if ($this->{$objCol}) { $where .= " and {$dbCol} = {$this->{$objCol}}"; //only bug: here I " and {$objCol} = {$this->$objCol}"; but with former experience, I know that database handling is the place where bug fills. So I var_dump($sql) and find it. } } $sql = "select * from {$this->table} {$where}"; // var_dump($sql); DataConnection::getConnection(); $rs = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($rs); while ($row) { $o = clone $this; foreach ($o->columns as $objCol => $dbCol) { $o->{$objCol} = $row[$dbCol]; } $result[] = $o; $row = mysql_fetch_array($rs); } return $result; }
/** * List items */ function menu_list($row_id = NULL, $search = NULL, $sort = NULL, $page = 1) { $view = new ListView(); // Row Id for update only row if (!empty($row_id)) { $row_id = 'id = ' . $row_id; } else { $row_id = 'id != 0'; } // Sort if (empty($sort)) { $sort = 'id ASC'; } $limit = PAGER_LIMIT; $offset = $page * $limit - $limit; $db = DataConnection::readOnly(); $total_records = 0; // Search if (!empty($search)) { $search_fields = array('id', 'label', 'func', 'module'); $exceptions = array(); $search_query = build_search_query($search, $search_fields, $exceptions); $menus = $db->menu()->where($row_id)->and($search_query)->order($sort)->limit($limit, $offset); } else { $menus = $db->menu()->where($row_id)->order($sort)->limit($limit, $offset); } $total_records = $db->menu()->count("*"); $i = 0; if (count($menus)) { // Building the header with sorter $headers[] = array('display' => 'Id', 'field' => 'id'); $headers[] = array('display' => 'Label', 'field' => 'label'); $headers[] = array('display' => 'Function', 'field' => 'func'); $headers[] = array('display' => 'Module', 'field' => 'module'); $headers[] = array('display' => 'Edit', 'field' => NULL); $headers[] = array('display' => 'Delete', 'field' => NULL); $headers = build_sort_header('menu_list', 'menu', $headers, $sort); foreach ($menus as $menu) { $j = $i + 1; //This is important for the row update/delete $rows[$j]['row_id'] = $menu['id']; ///////////////////////////////////////////// $rows[$j]['id'] = $menu['id']; $rows[$j]['label'] = $menu['label']; $rows[$j]['func'] = $menu['func']; $rows[$j]['module'] = $menu['module']; if ($menu['system'] == 1) { $disabled = 'disabled'; } else { $disabled = ''; } $rows[$j]['edit'] = theme_link_process_information('', 'menu_edit_form', 'menu_edit_form', 'menu', array('extra_value' => 'id|' . $menu['id'], 'response_type' => 'modal', 'icon' => NATURAL_EDIT_ICON, 'class' => $disabled)); $rows[$j]['delete'] = theme_link_process_information('', 'menu_delete_form', 'menu_delete_form', 'menu', array('extra_value' => 'id|' . $menu['id'], 'response_type' => 'modal', 'icon' => NATURAL_REMOVE_ICON, 'class' => $disabled)); $i++; } } $options = array('show_headers' => TRUE, 'page_title' => translate('Users List'), 'page_subtitle' => translate('Manage Menus'), 'empty_message' => translate('No menu found!'), 'table_prefix' => theme_link_process_information(translate('Create New Menu'), 'menu_create_form', 'menu_create_form', 'menu', array('response_type' => 'modal')), 'pager_items' => build_pager('menu_list', 'menu', $total_records, $limit, $page), 'page' => $page, 'sort' => $sort, 'search' => $search, 'show_search' => TRUE, 'function' => 'menu_list', 'module' => 'menu', 'update_row_id' => '', 'table_form_id' => '', 'table_form_process' => ''); $listview = $view->build($rows, $headers, $options); return $listview; }
public static function closeConnection() { if (isset(self::$connection)) { mysql_close(self::$connection) or die(mysql_error()); } self::$connection = null; }
/** * List items */ function report_list($row_id = NULL, $search = NULL, $sort = NULL, $page = 1) { $view = new ListView(); // Row Id for update only row if (!empty($row_id)) { $row_id = 'id = ' . $row_id; } else { $row_id = 'id != 0'; } // Sort if (empty($sort)) { $sort = 'id ASC'; } $limit = PAGER_LIMIT; $offset = $page * $limit - $limit; $db = DataConnection::readOnly(); $total_records = 0; // Search if (!empty($search)) { $search_fields = array('id', 'report_name', 'report_content'); $exceptions = array(); $search_query = build_search_query($search, $search_fields, $exceptions); $reports = $db->report()->where($row_id)->and($search_query)->order($sort)->limit($limit, $offset); } else { $reports = $db->report()->where($row_id)->order($sort)->limit($limit, $offset); } $total_records = $db->report()->count("*"); $i = 0; if (count($reports)) { // Building the header with sorter $headers[] = array('display' => 'Id', 'field' => 'id'); $headers[] = array('display' => 'Report Name', 'field' => 'report_name'); $headers[] = array('display' => 'Pdf', 'field' => NULL); $headers = build_sort_header('report_list', 'report', $headers, $sort); foreach ($reports as $report) { $j = $i + 1; //This is important for the row update/delete $rows[$j]['row_id'] = $report['id']; ///////////////////////////////////////////// $rows[$j]['id'] = $report['id']; $rows[$j]['report_name'] = $report['report_name']; $rows[$j]['Pdf'] = theme_link_process_information('Pdf', 'report_pdf', 'report_pdf', 'report', array('extra_value' => 'id|' . $report['id'], 'response_type' => 'modal')); $i++; } } $options = array('show_headers' => TRUE, 'page_title' => translate('Reports List'), 'page_subtitle' => translate('Generate Reports'), 'empty_message' => translate('No report found!'), 'pager_items' => build_pager('report_list', 'report', $total_records, $limit, $page), 'page' => $page, 'sort' => $sort, 'search' => $search, 'show_search' => TRUE, 'function' => 'report_list', 'module' => 'report', 'update_row_id' => '', 'table_form_id' => '', 'table_form_process' => ''); $listview = $view->build($rows, $headers, $options); return $listview; }
/** * Convert all strings to a different language */ function translate($string, $lang = 'en') { if ($lang == 'en' || $lang == null) { /** * Language is either default or missing so no translation * is necessary :D */ return $string; } $db = DataConnection::readOnly(); $lg = $db->language()->where('original', $string)->and('lang', $lang)->fetch(); if ($lg) { return $lg['translate']; } else { return $string; } }
public function find() { $result = array(); $where = 'where 1=1 '; foreach ($this->columns as $objCol => $dbCol) { if ($this->{$objCol}) { $where .= " and {$dbCol} = {$this->{$objCol}}"; } } $sql = "select * from {$this->table} {$where}"; DataConnection::getConnection(); $rs = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($rs); while ($row) { $o = clone $this; foreach ($o->columns as $objCol => $dbCol) { $o->{$objCol} = $row[$dbCol]; } $result[] = $o; $row = mysql_fetch_assoc($rs); } // print_r($result); return $result; }
session_start(); require_once 'bootstrap.php'; require_once 'modules/dashboard_widgets/dashboard_widgets.controller.php'; require_once 'modules/dashboard_widgets/dashboard_widgets_blocks.php'; if ($_SESSION['log_username']) { $_SESSION['dash_type'] = 1; $module = new Module(); //$module->loadSingle("module='dashboard' LIMIT 1"); //$_SESSION['dialer-version'] = NATURAL_VERSION . ' - r.' . $module->version; $username = $_SESSION['log_username']; $user_full_name = $_SESSION['log_first_name'] . ' ' . $_SESSION['log_last_name']; $version = NATURAL_VERSION; $_SESSION['log_interface'] = 'skin-gray'; $menu = new Menu(); // Twig Menu $menu_html = $twig->render('menu.html', array('links' => $menu->byLevel('main', $_SESSION['log_access_level']), 'first' => TRUE)); //Loading avatar picture $db = DataConnection::readOnly(); $file = $db->files[$_SESSION['log_file_id']]; if ($file) { $avatar = $file['uri']; } // Twig Base $template = $twig->loadTemplate('base.html'); $template->display(array('project_title' => TITLE, 'path_to_theme' => THEME_PATH, 'company' => NATURAL_COMPANY, 'version' => $version, 'page' => 'dashboard-main', 'menu' => $menu_html, 'avatar' => $avatar, 'user_full_name' => $user_full_name, 'username' => $username, 'actual_date' => date('F jS, Y'), 'page_title' => 'Dashboard', 'page_subtitle' => 'Widgets', 'content' => dashboard_content())); } else { $error_message = 'Invalid Login Information!'; $password = ''; $username = $_POST['username']; require_once 'index.php'; }
/** * Method to delete a transaction * * Delete transaction from database * * @url DELETE delete * @smart-auto-routing false * * @access public * @throws 404 Transaction not found * @return mixed */ function delete($id) { $data['id'] = $id; $this->_validate($data, "delete"); $db = DataConnection::readWrite(); $q = $db->transaction[$id]; $response = array(); if ($q && $q->delete()) { $response['code'] = 200; $response['message'] = 'Transaction has been removed!'; natural_set_message($response['message'], 'success'); return $response; } else { $response['code'] = 404; $response['message'] = 'Transaction not found!'; natural_set_message($response['message'], 'error'); throw new Luracast\Restler\RestException($response['code'], $response['message']); return $response; } }
/** * User Edit Form Builder. */ function user_edit_form($user_id) { $user = new User(); $user->byID($user_id); if ($user->affected > 0) { $frm = new DbForm(); // Select the properly levels $db = DataConnection::readOnly(); $access_levels = $db->acl_levels()->select('description, level')->where('level <= ? ', $_SESSION['log_access_level']); if (count($access_levels) > 0) { $items = array(); foreach ($access_levels as $access_level) { $items[] = ucwords($access_level['description']) . '=' . $access_level['level']; } $user->access_level_options = implode(';', $items); } // Testing chekboxes $user->user_race = array('caucasian', 'asian', 'indian'); // Testing radio buttons //$user->user_race = 'asian'; // Testing uploader - avatar field with fids $user->avatar = array($user->file_id); $frm->build('user_edit_form', $user, $_SESSION['log_access_level']); } else { natural_set_message('Problems loading user ' . $user_id, 'error'); return FALSE; } }
/** * @smart-auto-routing false * @access private */ function _validate($data, $type, $from_api = true) { //If the method called is an update, check if the id exists, otherwise return error if ($type == "update" || $type == "delete") { if (!$data['id']) { throw new Luracast\Restler\RestException(404, 'Parameter ID is required!'); } } /* * check if field is empty * Add more fields as needed */ if ($type != "delete") { if (!$data['position']) { $error[] = 'Field position is required!'; } if (!is_numeric($data['position'])) { $error[] = 'Field position must be numeric!'; } if (!$data['element_name']) { $error[] = 'Field Element Name is required!'; } if (!$data['label']) { $error[] = 'Field Label is required!'; } if (!$data['func']) { $error[] = 'Field Function is required!'; } $menu = new Menu(); $db = DataConnection::readOnly(); if ($type == "edit") { $menus = $db->menu()->select("*")->where("element_name", $data['element_name'])->and("id != ?", $data['id'])->limit(1); if (count($menus) > 0) { $error[] = 'Element name already in use, please try with a different element name!'; } } if ($type == "create") { $menus = $db->menu()->select("*")->where("element_name", $data['element_name'])->limit(1); if (count($menus)) { $error[] = 'Element name already in use, please try with a different element name!'; } } } //If error exists return or throw exception if the call has been made from the API if (!empty($error)) { natural_set_message($error[0], 'error'); if ($from_api) { throw new Luracast\Restler\RestException($error_code, $error[0]); } return $error; exit(0); } }
/** * @smart-auto-routing false * @access private */ public function updateUserStatus($status, $user_id) { $db = DataConnection::readWrite(); $u = $db->user[$user_id]; if ($u) { $data = array('status' => $status); $affected = $u->update($data); } }
function create_form($table_name) { //$ft = new DataManager; //$ff = new DataManager; $db = DataConnection::readOnly(); $dbform = new DbForm(); $dbfield = new DbField(); $param = ""; $fnm = ""; $param['form_method'] = "POST"; $form_add = $table_name . '_create_form'; $form_edit = $table_name . '_edit_form'; $form_delete = $table_name . '_delete_form'; //Saving form parameters for the create form $param['form_id'] = $form_add; $param['form_name'] = $form_add; $param['form_title'] = 'Add New ' . ucwords(str_replace("_", " ", strtolower($table_name))); $param['form_action'] = "javascript:process_information('" . $table_name . "_create_form', '" . $table_name . "_create_form_submit', '" . $table_name . "', null, null, null, null, 'create_row');"; //$ft->dmInsert("" . FORM_TABLE, $param); $create = $dbform->create($param); $form_add_id = $create['id']; //Saving form parameters for edit form $param['form_id'] = $form_edit; $param['form_name'] = $form_edit; $param['form_title'] = 'Edit ' . ucwords(str_replace("_", " ", strtolower($table_name))); $param['form_action'] = "javascript:process_information('" . $table_name . "_edit_form', '" . $table_name . "_edit_form_submit', '" . $table_name . "', null, null, null, null, 'edit_row');"; //$ft->dmInsert("" . FORM_TABLE, $param); $edit = $dbform->create($param); $form_edit_id = $edit['id']; //Saving form parameters for delete form $param['form_id'] = $form_delete; $param['form_name'] = $form_delete; $param['form_title'] = 'Delete ' . ucwords(str_replace("_", " ", strtolower($table_name))); $param['form_action'] = "javascript:process_information('" . $table_name . "_delete_form', '" . $table_name . "_delete_form_submit', '" . $table_name . "', null, null, null, null, 'delete_row');"; //$ft->dmInsert("" . FORM_TABLE, $param); $delete = $dbform->create($param); $form_delete_id = $delete['id']; //$dblink = mysql_connect(NATURAL_DBHOST, NATURAL_DBUSER, NATURAL_DBPASS); /*if (!$dblink) { //die('Could not connect: ' . mysql_error()); natural_set_message('Failed to connect with the database '.NATURAL_DBNAME.'!', 'error'); }*/ $today = date("m-d-Y H:i:s"); $now = date("M-D-Y"); $query = 'SHOW COLUMNS FROM ' . NATURAL_DBNAME . '.' . $table_name; $query_result = mysql_query($query, $dblink); $pdo = new PDO(NATURAL_PDO_DSN_READ, NATURAL_PDO_USER_READ, NATURAL_PDO_PASS_READ); $q = $pdo->prepare('SHOW COLUMNS FROM ' . NATURAL_DBNAME . '.' . $table_name); $q->execute(); $columns = $q->fetchAll(PDO::FETCH_COLUMN); $i = 0; if (count($columns) > 0) { foreach ($columns as $key => $val) { $label = ""; $nam_ar = explode("_", $val); if (is_array($nam_ar)) { for ($x = 0; $x < count($nam_ar); $x++) { if ($nam_ar[$x] != "id") { $label .= ucfirst($nam_ar[$x]) . " "; } } $label = substr($label, 0, -1); } else { $label = ucfirst($val); } $field['form_reference'] = $form_add; $field['form_template_id'] = $form_add_id; $field['field_id'] = $val; $field['field_name'] = $val; $field['form_field_order'] = $i; if ($val == "id") { $field['html_type'] = "hidden"; } else { $field['html_type'] = "text"; } $field['def_val'] = ""; $field['def_label'] = $label; //Insert template new //$ff->dmInsert("" . FIELD_TABLE, $field); $dbfield->create($field); //$form_add_id = $create['id']; //Insert template edit $field['form_reference'] = $form_edit; $field['form_template_id'] = $form_edit_id; $field['def_val'] = "{$val}"; $dbfield->create($field); if ($val == 'id') { //Insert delete id $field['form_reference'] = $form_delete; $field['form_template_id'] = $form_delete_id; $field['def_val'] = "{$val}"; $field['html_type'] = "hidden"; $field['def_label'] = 'ID'; $dbfield->create($field); } if ($i == 1) { //Insert delete message $field['form_reference'] = $form_delete; $field['form_template_id'] = $form_delete_id; $field['field_id'] = 'message'; $field['field_name'] = 'message'; $field['form_field_order'] = $i; $field['def_label'] = ''; $field['def_val'] = 'Are you sure you want to delete this ' . $table_name . '?'; $field['html_type'] = 'message'; $dbfield->create($field); //Insert delete object $field['form_reference'] = $form_delete; $field['form_template_id'] = $form_delete_id; $field['field_id'] = "{$val}"; $field['field_name'] = "{$val}"; $field['form_field_order'] = $i + 1; $field['def_label'] = ''; $field['def_val'] = "{$val}"; $field['html_type'] = 'message'; $dbfield->create($field); } $i++; } $field['form_reference'] = $form_add; $field['form_template_id'] = $form_add_id; $field['field_id'] = "sub"; $field['field_name'] = "sub"; $field['form_field_order'] = $i; $field['def_label'] = ''; $field['def_val'] = ''; $field['html_type'] = 'submit'; $dbfield->create($field); $field['form_reference'] = $form_edit; $field['form_template_id'] = $form_edit_id; $dbfield->create($field); $field['form_reference'] = $form_delete; $field['form_template_id'] = $form_delete_id; $dbfield->create($field); } natural_set_message('Done creating the form for the table ' . $table_name . '!', 'success'); }
<?php /** * @file: uploader_remove_file.php * Server Side Ajax Uplader */ session_start(); require_once '../../bootstrap.php'; // Load file infomartion $id = $_GET['id']; //$file = new Files(); // $file->loadSingle('id = ' . $id); // Get the file from the files table. $db = DataConnection::readWrite(); $file = $db->files[$id]; $arr['uid'] = $_SESSION['log_id']; $arr['filename'] = $_FILES['myfile']['name']; $arr['uri'] = $field_dir . '/' . $_FILES['myfile']['name']; $arr['filemime'] = $_FILES['myfile']['type']; $filename = $file['filename']; $uri = $file['uri']; if ($file['id'] < 1) { natural_set_message('Error loading file information.', 'error'); return FALSE; } // Remove file //$file->remove('id = ' . $id); if ($file && $file->delete()) { //if ($file->affected > 0) { unlink(NATURAL_ROOT_PATH . '/' . $uri); natural_set_message('File "' . $filename . '" was removed successfully.', 'success');
/** * Function for the user to Setup the Dashboard */ function dashboard_setup_form() { // Get the Dashboard Type $dashboard_type = $_SESSION['dash_type']; $db = DataConnection::readOnly(); $widgets = $db->dashboard_widgets()->where('enabled', 1)->and('dash_type', $_SESSION['dash_type']); if (count($widgets) > 0) { $pdo = new PDO(NATURAL_PDO_DSN_READ, NATURAL_PDO_USER_READ, NATURAL_PDO_PASS_READ); if ($_SESSION['log_church_id']) { $sql = "select dashboard from church_link\n where church_id = " . $_SESSION['log_church_id'] . " and user_id = " . $_SESSION['log_id']; } else { $sql = "select dashboard from user\n \t\t\t\t\t\t\t\t where user_id = " . $_SESSION['log_id']; } $conn = $pdo->prepare($sql); $conn->execute(); $u = $conn->fetchAll(PDO::FETCH_ASSOC); $currentset = json_decode(unserialize($u[0]['dashboard']), true); $checked = ''; foreach ($widgets as $widget) { foreach ($currentset as $current) { if ($current['id'] == $widget['id']) { $checked = 'checked="checked"'; break; } else { $checked = ''; } } $inputs[$widget['id']]['id'] = $widget['id']; $inputs[$widget['id']]['title'] = $widget['title']; $inputs[$widget['id']]['check'] = $checked; $inputs[$widget['id']]['fn'] = $widget['widget_function']; } } if ($inputs) { global $twig; $form = $twig->render('dashboard-setup.html', array('title' => 'Dashboard Setup', 'inputs' => $inputs)); } unset($pdo); unset($conn); unset($sql); return $form; }
/** * Function for the user to Setup the Dashboard */ function dashboard_setup_form() { // Get the Dashboard Type $dashboard_type = $_SESSION['dash_type']; $db = DataConnection::readOnly(); $widgets = $db->dashboard_widgets()->where('enabled', 1); if (count($widgets) > 0) { // Retrieve the widgets already selected by the user $user = new User(); $user->byID($_SESSION['log_id']); if ($user->dashboard) { $user_widgets = $user->dashboard; } $checked = ''; foreach ($widgets as $widget) { foreach ($user_widgets as $user) { if ($user['id'] == $widget['id']) { $checked = 'checked="checked"'; break; } else { $checked = ''; } } $inputs[$widget['id']]['id'] = $widget['id']; $inputs[$widget['id']]['title'] = $widget['title']; $inputs[$widget['id']]['check'] = $checked; $inputs[$widget['id']]['fn'] = $widget['widget_function']; } } if ($inputs) { global $twig; $form = $twig->render('dashboard-setup.html', array('title' => 'Dashboard Setup', 'inputs' => $inputs)); } return $form; }