Exemple #1
0
 function __construct($helpid = null)
 {
     $sql = 'select * from help where helpid="' . $helpid . '"';
     $help = Database::singleton()->query_fetch($sql);
     $this->title = $help['title'];
     $this->body = $help['body'];
 }
 /**
  * @url GET run
  * @param array $roleIds
  */
 public function run($roleIds = null)
 {
     try {
         $session = Session::singleton();
         $session->activateRoles($roleIds);
         // Check sessionRoles if allowedRolesForRunFunction is specified
         $allowedRoles = Config::get('allowedRolesForRunFunction', 'execEngine');
         if (!is_null($allowedRoles)) {
             $ok = false;
             foreach ($session->getSessionRoles() as $role) {
                 if (in_array($role->label, $allowedRoles)) {
                     $ok = true;
                 }
             }
             if (!$ok) {
                 throw new Exception("You do not have access to run the exec engine", 401);
             }
         }
         ExecEngine::run(true);
         $db = Database::singleton();
         $db->closeTransaction('Run completed', false, true, false);
         $result = array('notifications' => Notifications::getAll());
         return $result;
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }
/**
 * Adds the missing instruments based on the visit_label
 *
 * @param Array  $result      containing visit_label info
 * @param String $visit_label The name of the visit
 *
 * @return NULL
 */
function populateVisitLabel($result, $visit_label)
{
    global $argv, $confirm;
    // create a new battery object && new battery
    $battery = new NDB_BVL_Battery();
    // select a specific time point (sessionID) for the battery
    $battery->selectBattery($result['ID']);
    $timePoint = TimePoint::singleton($result['ID']);
    $DB = Database::singleton();
    $candidate = Candidate::singleton($result['CandID']);
    $result_firstVisit = $candidate->getFirstVisit();
    $isFirstVisit = false;
    //adding check for first visit
    if ($result_firstVisit == $visit_label) {
        $isFirstVisit = true;
    }
    //To assign missing instruments to all sessions, sent to DCC or not.
    $defined_battery = $battery->lookupBattery($battery->age, $result['subprojectID'], $timePoint->getCurrentStage(), $visit_label, $timePoint->getCenterID(), $isFirstVisit);
    $actual_battery = $battery->getBattery($timePoint->getCurrentStage(), $result['subprojectID'], $visit_label);
    $diff = array_diff($defined_battery, $actual_battery);
    if (!empty($diff)) {
        echo "\n CandID: " . $timePoint->getCandID() . "  Visit Label:  " . $timePoint->getVisitLabel() . "\nMissing Instruments:\n";
        print_r($diff);
    }
    if ($confirm === true) {
        foreach ($diff as $test_name) {
            $battery->addInstrument($test_name);
        }
    }
    unset($battery);
    unset($timePoint);
}
Exemple #4
0
function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
    $sql = 'select * from templates where path="' . $tpl_name . '" and module="' . $smarty_obj->compile_id . '" order by `timestamp` desc limit 1';
    $r = Database::singleton()->query_fetch($sql);
    $tpl_timestamp = strtotime($r['timestamp']);
    return true;
}
 public function getAdminInterface()
 {
     $st = "select ecomm_product.id as product_id, ecomm_product.name as product_name,\n\t\t\t\tecomm_product.supplier as supplier_id, ecomm_supplier.name as supplier_name, ecomm_product.price as product_price\n\t\t\t\tfrom ecomm_product left join ecomm_supplier on ecomm_product.supplier = ecomm_supplier.id\n\t\t\t\torder by ecomm_supplier.name,ecomm_product.name";
     $products = Database::singleton()->query_fetch_all($st);
     $formPath = "/admin/EComm&section=Plugins&page=ChangeProductPrice";
     $form = new Form('change_product_prices', 'post', $formPath);
     if ($form->validate() && isset($_REQUEST['submit'])) {
         foreach ($products as $product) {
             $ECommProduct = new Product($product['product_id']);
             $ECommProduct->setPrice($_REQUEST['product_' . $product['product_id']]);
             $ECommProduct->save();
         }
         return "Your products' prices have been changed successfully<br/><a href='{$formPath}'>Go back</a>";
     }
     $oldSupplier = 0;
     $currentSupplier = 0;
     $defaultValue = array();
     foreach ($products as $product) {
         $currentSupplier = $product['supplier_id'];
         if ($oldSupplier != $currentSupplier) {
             $form->addElement('html', '<br/><br/><hr/><h3>Supplier: ' . $product['supplier_name'] . '</h3>');
         }
         $form->addElement('text', 'product_' . $product['product_id'], $product['product_name']);
         $defaultValue['product_' . $product['product_id']] = $product['product_price'];
         $oldSupplier = $product['supplier_id'];
     }
     $form->addElement('submit', 'submit', 'Submit');
     $form->setDefaults($defaultValue);
     return $form->display();
 }
 /**
  * @url GET run
  */
 public function run()
 {
     try {
         $session = Session::singleton();
         $db = Database::singleton();
         $allowedRoles = (array) Config::get('allowedRolesForRunFunction', 'execEngine');
         if (Config::get('loginEnabled') && !is_null($allowedRoles)) {
             $ok = false;
             $sessionRoles = Role::getAllSessionRoles();
             foreach ($sessionRoles as $role) {
                 if (in_array($role->label, $allowedRoles)) {
                     $ok = true;
                 }
             }
             if (!$ok) {
                 throw new Exception("You do not have access to run the exec engine", 401);
             }
         }
         $session->setRole();
         ExecEngine::runAllRules();
         $db->closeTransaction('Run completed', false, true, false);
         $result = array('notifications' => Notifications::getAll());
         return $result;
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }
 public function GetGruposByID($id)
 {
     $bd = Database::singleton();
     $where = array("id" => $id);
     $result = $bd->Select("grupos", null, $where, null);
     return $result[0];
 }
 public function GetAlbunsByName($name)
 {
     $bd = Database::singleton();
     $where = array("nome" => $name);
     $result = $bd->Select("pastas", null, $where, null);
     return $result;
 }
 private static function saveMutation($operation, $fullRelationSignature, $stableAtom, $stableConcept, $modifiedAtom, $modifiedConcept, $source)
 {
     if (array_key_exists($fullRelationSignature, Config::get('mutationConcepts', 'MutationExtension'))) {
         Notifications::addLog("Save mutation on '{$fullRelationSignature}' (editUpdate)", 'Mutation');
         $mutConcept = Config::get('mutationConcepts', 'MutationExtension')[$fullRelationSignature];
         $database = Database::singleton();
         $database->setTrackAffectedConjuncts(false);
         // Don't track affected conjuncts for Mutation concept and relations;
         // New Mutation
         $mut = $database->addAtomToConcept(Concept::createNewAtom($mutConcept), $mutConcept);
         // Add mut info
         $database->editUpdate('mutRelation', false, $mut, 'Mutation', $fullRelationSignature, 'Relation');
         $database->editUpdate('mutDateTime', false, $mut, 'Mutation', date(DATE_ISO8601), 'DateTime');
         if ($source == 'User') {
             $user = Session::getSessionUserId();
         } else {
             $user = $source;
         }
         $database->editUpdate('mutBy', false, $mut, 'Mutation', $user, 'User');
         $database->editUpdate('mutOp', false, $mut, 'Mutation', $operation, 'Operation');
         // $database->editUpdate('mutReason', false, $mut, 'Mutation', 'zomaar', 'MutationReason'); // TODO: get reason from somewhere
         $database->editUpdate('mutValue', false, $mut, 'Mutation', $modifiedAtom, 'MutationValue');
         $database->editUpdate('mutStable', false, $mut, $mutConcept, $stableAtom, $stableConcept);
         $database->editUpdate('mutPublish', false, $mut, 'Mutation', $mut, 'Mutation');
         $database->setTrackAffectedConjuncts(true);
         // Enable tracking of affected conjuncts again!!
     }
 }
Exemple #10
0
 public static function getPropertiesBasedOnProductId($productId)
 {
     if (!$productId) {
         return new ProductPropertiesTbl();
     }
     $sql = 'select `id` from ecomm_product_properties where product = "' . e($productId) . '"';
     $result = Database::singleton()->query_fetch($sql);
     return new ProductPropertiesTbl($result['id']);
 }
Exemple #11
0
 public static function getAll()
 {
     $sql = 'select `id` from ecomm_transaction';
     $results = Database::singleton()->query_fetch_all($sql);
     foreach ($results as &$result) {
         $result = new Transaction($result['id']);
     }
     return $results;
 }
Exemple #12
0
 public static function getAllReports()
 {
     $sql = 'select mso_id from mail_sendout order by mso_timestamp desc';
     $rs = Database::singleton()->query_fetch_all($sql);
     foreach ($rs as &$r) {
         $r = new MailReport($r['mso_id']);
     }
     return $rs;
 }
Exemple #13
0
 public static function getPermissions()
 {
     $sql = 'select * from permissions';
     $p = Database::singleton()->query_fetch_all($sql);
     foreach ($p as &$perm) {
         $perm = new Permission($perm['id']);
     }
     return $p;
 }
 function setUp()
 {
     $client = new NDB_Client();
     $client->makeCommandLine();
     $client->initialize();
     $this->DB = Database::singleton();
     $this->DB->setFakeTableData("test_names", array(array('ID' => 1, 'Test_name' => 'ActiveTestByAge', 'Full_name' => 'Active Test 1', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 2, 'Test_name' => 'ActiveTestByAge2', 'Full_name' => 'Active Test 2', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 3, 'Test_name' => 'InactiveTest', 'Full_name' => 'Inactive Test 1', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 4, 'Test_name' => 'ActiveTestByVisit', 'Full_name' => 'Active Test by Visit 1', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 5, 'Test_name' => 'ActiveTestByVisit2', 'Full_name' => 'Active Test by Visit 2', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 6, 'Test_name' => 'ActiveTestByFirstVisit', 'Full_name' => 'Active Test by First Visit 2', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 7, 'Test_name' => 'ActiveTestByNotFirstVisit', 'Full_name' => 'Active Test by Not First Visit 2', 'Sub_group' => 1, 'IsDirectEntry' => 0)));
     $this->DB->setFakeTableData("test_battery", array(array('ID' => 1, 'Test_name' => 'ActiveTestByAge', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => null, 'firstVisit' => null), array('ID' => 2, 'Test_name' => 'ActiveTestByAge2', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => '1', 'firstVisit' => null), array('ID' => 3, 'Test_name' => 'InactiveTest', 'AgeMinDays' => 0, 'AgeMaxDays' => 0, 'Active' => 'N', 'Stage' => 'Visit', 'SubprojectID' => 2, 'Visit_label' => 'V01', 'CenterID' => '1', 'firstVisit' => null), array('ID' => 4, 'Test_name' => 'ActiveTestByVisit', 'AgeMinDays' => 0, 'AgeMaxDays' => 0, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 2, 'Visit_label' => 'V01', 'CenterID' => null, 'firstVisit' => null), array('ID' => 5, 'Test_name' => 'ActiveTestByVisit2', 'AgeMinDays' => 0, 'AgeMaxDays' => 0, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 2, 'Visit_label' => 'V01', 'CenterID' => '1', 'firstVisit' => null), array('ID' => 6, 'Test_name' => 'ActiveTestByFirstVisit', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => '1', 'firstVisit' => 'Y'), array('ID' => 7, 'Test_name' => 'ActiveTestByNotFirstVisit', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => '1', 'firstVisit' => 'N')));
 }
 function testSetFakeData()
 {
     $client = new NDB_Client();
     $client->makeCommandLine();
     $client->initialize();
     $DB = Database::singleton();
     $DB->setFakeTableData("Config", array(0 => array('ID' => 99999, 'ConfigID' => '123456', 'Value' => 'FKE1234')));
     $allCandidates = $DB->pselect("SELECT * FROM Config", array());
     $this->assertEquals($allCandidates, array(0 => array('ID' => 99999, 'ConfigID' => 123456, 'Value' => 'FKE1234')));
 }
Exemple #16
0
 public static function getCountryArray()
 {
     $sql = 'select id, name, codetwo, codethree, currency from countries';
     $r = Database::singleton()->query_fetch_all($sql);
     $array = array();
     foreach ($r as &$country) {
         $array[$country['id']] = $country['name'];
     }
     return $array;
 }
 public static function getAuthLevels()
 {
     $sql = "SELECT * FROM auth_groups";
     $result = Database::singleton()->query_fetch_all($sql);
     $level = array();
     foreach ($result as $row) {
         $levels[$row['agp_id']] = $row['agp_name'];
     }
     return $levels;
 }
Exemple #18
0
 public static function getStatesArray()
 {
     $sql = 'select id, name from states';
     $r = Database::singleton()->query_fetch_all($sql);
     $array = array();
     foreach ($r as &$state) {
         $array[$state['id']] = $state['name'];
     }
     return $array;
 }
/**
 * Get recruitment data for each month in the label array
 *
 * @param string $siteID ID of a site
 * @param array  $labels chart labels (months to query)
 *
 * @return array
 */
function getRecruitmentData($siteID, $labels)
{
    $DB = Database::singleton();
    $data = array();
    foreach ($labels as $label) {
        $month = strlen($label) == 6 ? substr($label, 0, 1) : substr($label, 0, 2);
        $year = substr($label, -4, 4);
        $data[] = $DB->pselectOne("SELECT COUNT(c.CandID)\n             FROM candidate c\n             WHERE c.CenterID=:Site\n             AND MONTH(c.Date_registered)=:Month\n             AND YEAR(c.Date_registered)=:Year\n             AND c.Entity_type='Human'", array('Site' => $siteID, 'Month' => $month, 'Year' => $year));
    }
    return $data;
}
/**
 * Gets the training quiz informations from the database
 *
 * @param string $instrumentID The ID of the instrument
 *
 * @return string
 */
function getQuizData($instrumentID)
{
    $DB = Database::singleton();
    // Get the questions
    $questions = $DB->pselect("SELECT Question, OrderNumber, ID \n         FROM certification_training_quiz_questions \n         WHERE TestID=:TID \n         ORDER BY OrderNumber", array('TID' => $instrumentID));
    // Add the array of answers to each question
    foreach ($questions as $i => $question) {
        $questions[$i]['answers'] = $DB->pselect("SELECT a.Answer, a.OrderNumber\n             FROM certification_training_quiz_answers a\n             LEFT JOIN certification_training_quiz_questions q\n             ON (a.QuestionID=q.ID) \n             WHERE q.TestID=:TID AND a.QuestionID=:QID\n             ORDER BY OrderNumber", array('TID' => $instrumentID, 'QID' => $question['ID']));
    }
    return $questions;
}
Exemple #21
0
 public static function openDB($dbname, $user, $password, $host, $port, $type)
 {
     if (is_null(self::$singleton)) {
         self::$singleton = new PDO("{$type}:host={$host};port={$port};dbname={$dbname}", $user, $password);
         // Création de la connexion
         self::$singleton->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         self::$singleton->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
         self::$singleton->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
         self::$singleton->query("SET NAMES 'utf8'");
     }
 }
/**
 * Get scan data for each month in the label array
 *
 * @param string $siteID ID of a site
 * @param array  $labels chart labels (months to query)
 *
 * @return array
 */
function getScanData($siteID, $labels)
{
    $DB = Database::singleton();
    $data = array();
    foreach ($labels as $label) {
        $month = strlen($label) == 6 ? substr($label, 0, 1) : substr($label, 0, 2);
        $year = substr($label, -4, 4);
        $data[] = $DB->pselectOne("SELECT COUNT(distinct s.ID) \n             FROM files f\n             LEFT JOIN mri_acquisition_dates mad ON (mad.SessionID=f.SessionID)\n             LEFT JOIN session s ON (s.ID=f.SessionID) \n             WHERE s.CenterID=:Site\n             AND MONTH(mad.AcquisitionDate)=:Month \n             AND YEAR(mad.AcquisitionDate)=:Year", array('Site' => $siteID, 'Month' => $month, 'Year' => $year));
    }
    return $data;
}
Exemple #23
0
 public static function sharedDB()
 {
     if (Database::$singleton === null) {
         $config = self::$remoteConfig;
         Database::$singleton = new mysqli($config["host"], $config["user"], $config["pass"], $config["db"], $config["port"]);
         $connection = Database::$singleton;
         if ($connection->connect_error) {
             die("Connection failed: " . $connection->connect_error);
         }
     }
     return Database::$singleton;
 }
Exemple #24
0
 public static function getAll($filter = true)
 {
     $sql = 'select `id` from ecomm_session';
     if ($filter) {
         $sql .= " where status = 1";
     }
     $results = Database::singleton()->query_fetch_all($sql);
     foreach ($results as &$result) {
         $result = new Session($result['id']);
     }
     return $results;
 }
Exemple #25
0
 public static function getAll($filter = true)
 {
     $sql = 'select `id` from ecomm_product_type';
     if ($filter) {
         $sql .= ' where status = 1';
     }
     $results = Database::singleton()->query_fetch_all($sql);
     foreach ($results as &$result) {
         $result = new ProductType($result['id']);
     }
     return $results;
 }
Exemple #26
0
 public static function getAll($orderId = 0)
 {
     $sql = 'select `id` from ecomm_order_detail';
     if ($orderId) {
         $sql .= " where order_nb = '" . e($orderId) . "'";
     }
     $sql .= " order by id";
     $results = Database::singleton()->query_fetch_all($sql);
     foreach ($results as &$result) {
         $result = new OrderDetail($result['id']);
     }
     return $results;
 }
Exemple #27
0
 public static function getUserDetailsBasedOnUserId($userId)
 {
     $sql = 'select `id` from ecomm_user_details where user = "******"';
     $result = Database::singleton()->query_fetch($sql);
     if (!@$result['id']) {
         $obj = new UserDetails();
         $obj->setUser($userId);
         $obj->save();
     } else {
         $obj = new UserDetails($result['id']);
     }
     return $obj;
 }
Exemple #28
0
 public static function getAll($sessionId = 0)
 {
     $sql = 'select `id` from ecomm_paypal_ipn';
     if ($sessionId) {
         $sql .= " where session = '" . e($sessionId) . "'";
     }
     $sql .= " order by id";
     $results = Database::singleton()->query_fetch_all($sql);
     foreach ($results as &$result) {
         $result = new PaypalIPN($result['id']);
     }
     return $results;
 }
Exemple #29
0
 public function __construct($id, $concept, $viewId = null)
 {
     $this->database = Database::singleton();
     // Ampersand attributes
     $this->id = $id;
     $this->concept = $concept;
     // View & label
     $this->view = $this->getView($viewId);
     $this->label = is_null($this->view) ? $this->id : implode($this->view);
     // no view? label = id
     // JSON-LD attributes
     $this->jsonld_id = Config::get('serverURL') . Config::get('apiPath') . '/resource/' . $concept . '/' . $this->id;
     $this->jsonld_type = Config::get('serverURL') . Config::get('apiPath') . '/concept/' . $concept;
 }
Exemple #30
0
 function __construct($preparedStmt)
 {
     if (!self::$thelink) {
         self::$thelink = Database::singleton()->link;
     }
     $this->preparedStmt = $preparedStmt;
     if (func_num_args() == 1) {
         $this->types = '';
     } else {
         $this->types = func_get_arg(1);
     }
     // OLD CONSTRUCTOR USED TO ACCEPT A SECOND ARUGUMENT WHICH IS AN OBJECT TO POPULATE.
     // if (func_num_args() == 2) $this->obj = new stdClass; else $this->obj = func_get_arg(2);
 }