public static function saveSession()
 {
     $engine = EngineAPI::singleton();
     $localvars = localvars::getInstance();
     $db = db::get($localvars->get('dbConnectionName'));
     $sql = "INSERT INTO `session`(username,sessionPages,ipAddr) VALUES(?,?,?)";
     $validate = new validate();
     $username = session::get('username');
     $pages = session::get('loggedPages');
     $pages = dbSanitize(implode(',', $pages));
     $ip = $_SERVER['REMOTE_ADDR'];
     $sqlArray = array($username, $pages, $ip);
     $db->beginTransaction();
     try {
         $sqlResult = $db->query($sql, $sqlArray);
         if ($sqlResult->error()) {
             throw new Exception("ERROR SQL" . $sqlResult->errorMsg());
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollback();
         $localvars->set('feedback', $e->getMessage());
         errorHandle::errorMsg($e->getMessage());
     }
 }
function getCompanyName($id)
{
    $localvars = localvars::getInstance();
    $validate = new validate();
    $customers = new Customers();
    $returnValue = "";
    if (isnull($id) && !$validate->integer($id)) {
        throw new Exception('not valid integer');
        return false;
    } else {
        $data = $customers->getRecords($id);
        $returnValue = $data[0]['companyName'];
        return $returnValue;
    }
}
 public function setupForm($id = null)
 {
     try {
         // call engine
         $engine = EngineAPI::singleton();
         $localvars = localvars::getInstance();
         $validate = new validate();
         // create customer form
         $form = formBuilder::createForm('TimeTracker');
         $form->linkToDatabase(array('table' => 'timeTracking'));
         if (!is_empty($_POST) || session::has('POST')) {
             $processor = formBuilder::createProcessor();
             $processor->processPost();
         }
         // form titles
         $form->insertTitle = "";
         $form->editTitle = "";
         $form->updateTitle = "";
         // if no valid id throw an exception
         if (!$validate->integer($id) && !isnull($id)) {
             throw new Exception(__METHOD__ . '() - Not a valid integer, please check the integer and try again.');
         }
         // form information
         $form->addField(array('name' => 'timeID', 'type' => 'hidden', 'value' => $id, 'primary' => TRUE, 'fieldClass' => 'id', 'showIn' => array(formBuilder::TYPE_INSERT, formBuilder::TYPE_UPDATE)));
         $form->addField(array('name' => 'projectIdLink', 'type' => 'hidden', 'label' => 'Project ID:', 'required' => TRUE, 'fieldClass' => 'projectID'));
         $form->addField(array('name' => 'customerIdLink', 'type' => 'hidden', 'label' => 'Customer ID:', 'fieldClass' => 'customerID', 'required' => TRUE));
         $form->addField(array('name' => 'startTime', 'type' => 'hidden', 'label' => 'start time:', 'fieldClass' => 'startTime', 'required' => TRUE));
         $form->addField(array('name' => 'endTime', 'type' => 'hidden', 'label' => 'end time:', 'fieldClass' => 'endTime', 'required' => TRUE));
         $form->addField(array('name' => 'totalHours', 'type' => 'hidden', 'label' => 'total time:', 'required' => TRUE, 'fieldClass' => 'totalHours'));
         $form->addField(array('name' => "completed", 'label' => "Has this project been completed?", 'showInEditStrip' => TRUE, 'type' => 'boolean', 'duplicates' => TRUE, 'options' => array("YES", "N0")));
         $form->addField(array('name' => "descriptionOfWork", 'label' => "Enter a description of the project:", 'type' => 'textarea'));
         // buttons and submissions
         $form->addField(array('showIn' => array(formBuilder::TYPE_UPDATE), 'name' => 'update', 'type' => 'submit', 'fieldClass' => 'submit', 'value' => 'Update'));
         $form->addField(array('showIn' => array(formBuilder::TYPE_UPDATE), 'name' => 'delete', 'type' => 'delete', 'fieldClass' => 'delete hidden', 'value' => 'Delete'));
         $form->addField(array('showIn' => array(formBuilder::TYPE_INSERT), 'name' => 'insert', 'type' => 'submit', 'fieldClass' => 'submit', 'value' => 'Submit'));
         return '{form name="TimeTracker" display="form"}';
     } catch (Exception $e) {
         errorHandle::errorMsg($e->getMessage());
     }
 }
function displayRoute($url, $vars)
{
    $localvars = localvars::getInstance();
    $model = isset($vars['model']) ? $vars['model'] : null;
    $action = isset($vars['action']) ? $vars['action'] : null;
    $item = isset($vars['item']) ? $vars['item'] : null;
    // expected pages
    $expectedModels = array('customers', 'projects', 'timeTracker');
    if (in_array($model, $expectedModels)) {
        $pageVariables = array('model' => ucfirst($model), 'action' => $action, 'item' => $item);
        $view = new View($model, $pageVariables);
    } else {
        if (isnull($model) || $model == "/" || $model == "home") {
            $pageVariables = array('model' => ucfirst($model));
            $view = new View('Home', $pageVariables);
        } else {
            $pageVariables = array('model' => ucfirst($model));
            // send to 404 error
            $view = new View('Error', $pageVariables);
        }
    }
    $html = $view->render();
    $localvars->set('content', $html);
}
<?php

$localvars = localvars::getInstance();
$localvars->set('siteRoot', '/');
$localvars->set('dbConnectionName', 'appDB');
$localvars->set("meta_authors", "");
$localvars->set('appName', "");
 public static function numCompleted($user)
 {
     $engine = EngineAPI::singleton();
     $localvars = localvars::getInstance();
     $db = db::get($localvars->get('dbConnectionName'));
     $sql = "SELECT * FROM `completed` WHERE username=?";
     $sqlArray = array(dbSanitize($user));
     $sqlResult = $db->query($sql, $sqlArray);
     if ($sqlResult->error()) {
         return false;
     } else {
         return $sqlResult->rowCount();
     }
 }
示例#7
0
 /**
  * =========================================================
  * Checks logic for searching if user email is in the system
  * this will help to provide a way to make sure that users
  * are not duplicated in the system.
  * =========================================================
  **/
 public static function checkEmail($email)
 {
     $engine = EngineAPI::singleton();
     $localvars = localvars::getInstance();
     $db = db::get($localvars->get('dbConnectionName'));
     $sql = "SELECT `email` FROM `users` WHERE `email`=? LIMIT=1";
     $email = dbSanitize($email);
     $sqlResult = $db->query($sql, array($email));
     try {
         if ($sqlResult->error()) {
             throw new Exception("Error Getting Entries");
         }
         if ($sqlResult->rowCount() < 1) {
             return false;
         } else {
             return true;
         }
     } catch (Exception $e) {
         errorHandle::errorMsg($e->getMessage());
     }
 }
 public function getCustomerProjectsJSON($customerID)
 {
     try {
         // call engine
         $engine = EngineAPI::singleton();
         $localvars = localvars::getInstance();
         $db = db::get($localvars->get('dbConnectionName'));
         $sql = "SELECT * FROM `projects`";
         $validate = new validate();
         // test to see if Id is present and valid
         if (!isnull($customerID) && $validate->integer($customerID)) {
             $sql .= sprintf('WHERE customerID = %s', $customerID);
         }
         // if no valid id throw an exception
         if (!$validate->integer($customerID) && !isnull($customerID)) {
             throw new Exception("An invalid ID was given!");
         }
         // get the results of the query
         $sqlResult = $db->query($sql);
         // if return no results
         // else return the data
         if ($sqlResult->rowCount() < 1) {
             return "There are no projects in the database.";
         } else {
             $data = array();
             while ($row = $sqlResult->fetch()) {
                 $data[] = $row;
             }
             return json_encode($data);
         }
     } catch (Exception $e) {
         errorHandle::errorMsg($e->getMessage());
     }
 }
 public function renderDataTable()
 {
     try {
         $engine = EngineAPI::singleton();
         $localvars = localvars::getInstance();
         $validate = new validate();
         $dataRecord = self::getRecords();
         $records = "";
         foreach ($dataRecord as $data) {
             $records .= sprintf("<tr>\n                                        <td>%s</td>\n                                        <td>%s</td>\n                                        <td>%s</td>\n                                        <td>%s</td>\n                                        <td>%s</td>\n                                        <td>%s</td>\n                                        <td><a href='customers/edit/%s'><span class='glyphicon glyphicon-edit'></span> </a></td>\n                                        <td><a href='customers/confirmDelete/%s'> <span class='glyphicon glyphicon-trash'></span> </a></td>\n                                    </tr>", $data['companyName'], $data['firstName'], $data['lastName'], $data['email'], $data['phone'], $data['website'], $data['ID'], $data['ID']);
         }
         $output = sprintf("<div class='dataTable table-responsive'>\n                                        <table class='table table-striped'>\n                                            <thead>\n                                                <tr class='info'>\n                                                    <th> Company Name </th>\n                                                    <th> First name </th>\n                                                    <th> Last Name </th>\n                                                    <th> Email </th>\n                                                    <th> Phone Number </th>\n                                                    <th> Website </th>\n                                                    <th> </th>\n                                                    <th> </th>\n                                                </tr>\n                                            </thead>\n                                            <tbody>\n                                                %s\n                                            </tbody>\n                                        </table>\n                                    </div>", $records);
         return $output;
     } catch (Exception $e) {
         errorHandle::errorMsg($e->getMessage());
         return $e->getMessage();
     }
 }