/** * Execute Query to obtain one or more objects from the NECLIMS db; returns string on error * * @param $sql * @param optional class specification */ function query($sql, $object = NULL) { // include object class if specifed if ($object != NULL) { require_once $object . ".cls.php"; } // create a data access object $dao = new DAO(); // pass the sql statement to the data access object $dao->setSQL($sql); // declare an array for storing the row results $retVal = array(); try { // run the sql statement if ($dao->execute() && sqlsrv_has_rows($dao->getResultSet())) { // object specified. if ($object != NULL) { // while there were more results/rows, save the object in the array while ($row = sqlsrv_fetch_object($dao->getResultSet(), $object . "")) { $retVal[] = $row; } } else { // while there were more results/rows, save the object in the array while ($row = sqlsrv_fetch_array($dao->getResultSet(), SQLSRV_FETCH_ASSOC)) { $retVal[] = $row; } } } } catch (Exception $e) { return "Query Error: " . $e->getMessage() . ". SQL: " . $sql . ". Object specified: " . $object; } // return to the caller return $retVal; //error_log(print_r($retVal, true)); }
/** * Dumps the Founder data into a table * * @param int $CompanyID */ function dumpFounderData($CompanyID) { // include the data access class include_once "DAO.php"; try { // create a new data access object $db = new DAO(); $sql = "EXEC dbo.GetFounderByCompanyID @CompanyID = " . $CompanyID; // set the select statement $db->setSQL($sql); // execute the SQL if ($db->execute()) { // did we get some rows if (sqlsrv_has_rows($db->getResultSet())) { // output the table and the first row (column headers) echo '<br>'; echo '<table class="sorted table-autosort:0 table-stripeclass:alternate">'; echo "<thead><tr>"; echo "<th class='table-sortable:default' width='100'>Name</th>"; echo "</tr></thead><tbody>"; // output the table rows while ($row = sqlsrv_fetch_array($db->getResultSet(), SQLSRV_FETCH_ASSOC)) { echo '<tr><td class="left" width="70"><a href="../Participant/History.php?wfID=' . $row['ID'] . '" target="_blank">' . $row['FounderName'] . '</a></td></tr>'; } // finish the table echo "</tbody></table>"; } else { echo "<div class='err'>No data found.</div>"; } } } catch (Exception $e) { echo $e->getMessage(), "\n"; } echo "</br>"; }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { //Include the ADOdb Library global $global, $dao; $global = array('approot' => realpath(dirname(__FILE__)) . '/../../../'); $dao = new DAO($global['db']); require_once $global['approot'] . '3rd/adodb/adodb.inc.php'; //Make the connection to $global['db'] $global['db'] = NewADOConnection('mysql'); $global['db']->Connect(TEST_DB_HOST, TEST_DB_USER, TEST_DB_PASSWD, TEST_DB_NAME); // test valid user $dao->execute("insert into users (user_name, p_uuid) values ('test1', 'any_p_uuid1')"); $dao->execute("insert into users (user_name, p_uuid) values ('vtest2', 'any_p_uuid2')"); $dao->execute("delete from users where user_name = 'test3'"); $dao->execute("delete from users where user_name = 'test4'"); }
function dumpParticipantWorkFlows($DONOR_CODE) { // include the data access class include_once "DAO.php"; try { // create a new data access object $db = new DAO(); // set the SQL $sql = "EXEC dbo.GetParticipantWorkFlows @DONOR_CODE ='" . $DONOR_CODE . "'"; // set the select statement $db->setSQL($sql); // execute the SQL if ($db->execute()) { // did we get some rows if (sqlsrv_has_rows($db->getResultSet())) { // output the table and the first row (column headers) echo '<br>'; echo '<table class="sorted table-autosort:0 table-stripeclass:alternate">'; echo "<thead><tr>"; echo "<th class='table-sortable:default' width='70'>Name</th>"; echo "<th class='table-sortable:default' width='295'>Description</th>"; echo "<th class='table-sortable:default' width='75'>Status</th>"; echo "<th class='table-sortable:default' width='150'>Next step</th>"; echo "<th class='table-sortable:default' width='200'>Next step role</th>"; echo "</tr></thead><tbody>"; // output the table rows while ($row = sqlsrv_fetch_array($db->getResultSet(), SQLSRV_FETCH_ASSOC)) { echo '<tr><td class="left" width="70"><a href="../Participant/History.php?wfID=' . $row['ID'] . '" target="_blank">' . $row['Name'] . '</a></td>'; echo '<td class="left" width="295">' . $row['Description'] . '</td>'; echo '<td class="center" width="75">' . $row['WorkFlowStatus'] . '</td>'; echo '<td class="left" width="150">' . $row['NextStep'] . '</td>'; echo '<td class="left" width="200">' . $row['Role'] . '</td></tr>'; } // finish the table echo "</tbody></table>"; } else { echo "<div class='err'>No data found.</div>"; } } } catch (Exception $e) { echo $e->getMessage(), "\n"; } echo "</br>"; }
$subquery = "(SELECT term FROM " . TABLE_PREFIX . "language_text\n\t\t\t\t\t\t\t\t\t\tWHERE language_code='" . $_REQUEST['lang_code'] . "'\n\t\t\t\t\t\t\t\t\t\t AND text <> '')"; if ($_REQUEST['new_or_translated'] == 1) { $sql .= " AND term NOT IN " . $subquery; } if ($_REQUEST['new_or_translated'] == 2) { $sql .= " AND term IN " . $subquery; } } if (isset($_REQUEST['new_or_translated']) && $_REQUEST['new_or_translated'] == 3) { $sql = "select * from " . TABLE_PREFIX . "language_text a \n\t\t\t\t\t\t\twhere language_code='" . DEFAULT_LANGUAGE_CODE . "' \n\t\t\t\t\t\t\t\tand exists (select 1 from " . TABLE_PREFIX . "language_text b \n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere language_code = '" . $_REQUEST['lang_code'] . "' \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand a.term = b.term \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand a.revised_date > b.revised_date)"; } } if (isset($_REQUEST['search'])) { $sql = "SELECT * FROM " . TABLE_PREFIX . "language_text \n\t\t\t\t\t\tWHERE language_code='" . DEFAULT_LANGUAGE_CODE . "'\n\t\t\t\t\t\t AND lower(term) like '%" . $addslashes(strtolower(trim($_REQUEST['search_phase']))) . "%'"; } $rows = $dao->execute($sql); if (is_array($rows)) { $num_results = count($rows); } else { $num_results = 0; } } if (isset($_REQUEST["save"])) { $sql_save = "REPLACE INTO " . TABLE_PREFIX . "language_text VALUES ('" . $_POST["lang_code"] . "', '" . $_POST["variable"] . "', '" . $_POST["term"] . "', '" . $addslashes($_POST["translated_text"]) . "', NOW(), '')"; $trans = get_html_translation_table(HTML_ENTITIES); $trans = array_flip($trans); $sql_save = strtr($sql_save, $trans); if (!$dao->execute($sql_save)) { $success_error = '<div class="error">Error: changes not saved!</div>'; } else { $success_error = '<div class="feedback2"">Success: changes saved.</div>';
/** * replace source object with alternatives according to user's preferences * @access public * @param $cid: content id. * @param $content: the original content page ($content_row['text'], from content.php). * @param $info_only: when "true", return the array of info (has_text_alternative, has_audio_alternative, has_visual_alternative, has_sign_lang_alternative) * @param $only_on_secondary_type: * @return string $content: the content page with the appropriated resources. * @see $db from include/vitals.inc.php * @author Cindy Qi Li */ public static function applyAlternatives($cid, $content, $info_only = false, $only_on_secondary_type = 0) { global $db, $_course_id; include_once TR_INCLUDE_PATH . 'classes/DAO/DAO.class.php'; $dao = new DAO(); $video_exts = array("mpg", "avi", "wmv", "mov", "swf", "mp4", "flv"); $audio_exts = array("mp3", "wav", "ogg", "mid"); $audio_width = 425; $audio_height = 27; $txt_exts = array("txt", "html", "htm"); $image_exts = array("gif", "bmp", "png", "jpg", "jpeg", "png", "tif"); $only_on_secondary_type = intval($only_on_secondary_type); // intialize the 4 returned values when $info_only is on if ($info_only) { $has_text_alternative = false; $has_audio_alternative = false; $has_visual_alternative = false; $has_sign_lang_alternative = false; } if (!$info_only && !$only_on_secondary_type && $_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT'] == 0 && $_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO'] == 0 && $_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL'] == 0) { //No user's preferences related to content format are declared if (!$info_only) { return $content; } else { return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative); } } // get all relations between primary resources and their alternatives $sql = "SELECT DISTINCT c.content_path, pr.resource, prt.type_id primary_type,\r\n sr.secondary_resource, srt.type_id secondary_type\r\n\t\t FROM " . TABLE_PREFIX . "primary_resources pr, " . TABLE_PREFIX . "primary_resources_types prt," . TABLE_PREFIX . "secondary_resources sr," . TABLE_PREFIX . "secondary_resources_types srt," . TABLE_PREFIX . "content c\r\n\t\t WHERE pr.content_id=" . $cid . "\r\n\t\t\t AND pr.primary_resource_id = prt.primary_resource_id\r\n\t\t\t AND pr.primary_resource_id = sr.primary_resource_id\r\n\t\t\t AND sr.language_code='" . $_SESSION['lang'] . "'\r\n\t\t\t AND sr.secondary_resource_id = srt.secondary_resource_id\r\n\t\t AND pr.content_id = c.content_id"; if ($only_on_secondary_type > 0) { $sql .= " AND srt.type_id=" . $only_on_secondary_type; } $sql .= " ORDER BY pr.primary_resource_id, prt.type_id"; $rows = $dao->execute($sql); if (!is_array($rows)) { if (!$info_only) { return $content; } else { return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative); } } $primary_resource_names = array(); foreach ($rows as $row) { // if the primary resource is defined with multiple resource type, // the primary resource would be replaced/appended multiple times. // This is what we want at applying alternatives by default, but // not when only one secondary type is chosen to apply. // This fix is to remove the duplicates on the same primary resource. // A dilemma of this fix is, for example, if the primary resource type // is "text" and "visual", but // $_SESSION['prefs']['PREF_ALT_TO_TEXT_APPEND_OR_REPLACE'] == 'replace' // $_SESSION['prefs']['PREF_ALT_TO_VISUAL_APPEND_OR_REPLACE'] == 'append' // so, should replace happen or append happen? With this fix, whichever // the first in the sql return gets preserved in the array and processed. // The further improvement is requried to keep rows based on the selected // secondary type (http://www.atutor.ca/atutor/mantis/view.php?id=4598). if ($only_on_secondary_type > 0) { if (in_array($row['resource'], $primary_resource_names)) { continue; } else { $primary_resource_names[] = $row['resource']; } } $alternative_rows[] = $row; $youtube_playURL = ContentUtility::convertYoutubeWatchURLToPlayURL($row['resource']); if ($row['resource'] != $youtube_playURL) { $row['resource'] = $youtube_playURL; $alternative_rows[] = $row; } } foreach ($alternative_rows as $row) { if ($info_only || $only_on_secondary_type || $_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT'] == 1 && $row['primary_type'] == 3 && ($_SESSION['prefs']['PREF_ALT_TO_TEXT'] == "audio" && $row['secondary_type'] == 1 || $_SESSION['prefs']['PREF_ALT_TO_TEXT'] == "visual" && $row['secondary_type'] == 4 || $_SESSION['prefs']['PREF_ALT_TO_TEXT'] == "sign_lang" && $row['secondary_type'] == 2) || $_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO'] == 1 && $row['primary_type'] == 1 && ($_SESSION['prefs']['PREF_ALT_TO_AUDIO'] == "visual" && $row['secondary_type'] == 4 || $_SESSION['prefs']['PREF_ALT_TO_AUDIO'] == "text" && $row['secondary_type'] == 3 || $_SESSION['prefs']['PREF_ALT_TO_AUDIO'] == "sign_lang" && $row['secondary_type'] == 2) || $_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL'] == 1 && $row['primary_type'] == 4 && ($_SESSION['prefs']['PREF_ALT_TO_VISUAL'] == "audio" && $row['secondary_type'] == 1 || $_SESSION['prefs']['PREF_ALT_TO_VISUAL'] == "text" && $row['secondary_type'] == 3 || $_SESSION['prefs']['PREF_ALT_TO_VISUAL'] == "sign_lang" && $row['secondary_type'] == 2)) { $ext = substr($row['secondary_resource'], strrpos($row['secondary_resource'], '.') + 1); // alternative is video if (in_array($ext, $video_exts) || in_array($ext, $audio_exts) || preg_match("/http:\\/\\/.*youtube.com\\/watch.*/", $row['secondary_resource'])) { if (in_array($ext, $audio_exts)) { // display audio medias in a smaller width/height (425 * 27) // A hack for now to handle audio media player size $target = '[media|' . $audio_width . '|' . $audio_height . ']' . $row['secondary_resource'] . '[/media]'; } else { // use default media size for video medias $target = '[media]' . $row['secondary_resource'] . '[/media]'; } } else { if (in_array($ext, $txt_exts)) { if ($row['content_path'] != '') { $file_location = $row['content_path'] . '/' . $row['secondary_resource']; } else { $file_location = $row['secondary_resource']; } $file = TR_CONTENT_DIR . $_SESSION['course_id'] . '/' . $file_location; $target = '<br />' . file_get_contents($file); // check whether html file if (preg_match('/.*\\<html.*\\<\\/html\\>.*/s', $target)) { // is a html file, use iframe to display // get real path to the text file if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) { $course_base_href = 'get.php/'; } else { $course_base_href = 'content/' . $_SESSION['course_id'] . '/'; } $file = TR_BASE_HREF . $course_base_href . $file_location; $target = '<iframe width="100%" frameborder="0" class="autoHeight" scrolling="auto" src="' . $file . '"></iframe>'; } else { // is a text file, insert/replace into content $target = nl2br($target); } } else { if (in_array($ext, $image_exts)) { $target = '<img border="0" alt="' . _AT('alternate_text') . '" src="' . $row['secondary_resource'] . '"/>'; } else { $target = '<p><a href="' . $row['secondary_resource'] . '">' . $row['secondary_resource'] . '</a></p>'; } } } // replace or append the target alternative to the source if ($row['primary_type'] == 3 && $_SESSION['prefs']['PREF_ALT_TO_TEXT_APPEND_OR_REPLACE'] == 'replace' || $row['primary_type'] == 1 && $_SESSION['prefs']['PREF_ALT_TO_AUDIO_APPEND_OR_REPLACE'] == 'replace' || $row['primary_type'] == 4 && $_SESSION['prefs']['PREF_ALT_TO_VISUAL_APPEND_OR_REPLACE'] == 'replace') { $pattern_replace_to = '${1}' . "\n" . $target . "\n" . '${3}'; } else { $pattern_replace_to = '${1}${2}' . "<br /><br />\n" . $target . "\n" . '${3}'; } // *** Alternative replace/append starts from here *** $processed = false; // one primary resource is only processed once // append/replace target alternative to [media]source[/media] if (!$processed && preg_match("/" . preg_quote("[media") . ".*" . preg_quote("]" . $row['resource'] . "[/media]", "/") . "/sU", $content)) { $processed = true; if (!$info_only) { $content = preg_replace("/(.*)(" . preg_quote("[media") . ".*" . preg_quote("]" . $row['resource'] . "[/media]", "/") . ")(.*)/sU", $pattern_replace_to, $content); } else { if ($row['secondary_type'] == 1) { $has_audio_alternative = true; } if ($row['secondary_type'] == 2) { $has_sign_lang_alternative = true; } if ($row['secondary_type'] == 3) { $has_text_alternative = true; } if ($row['secondary_type'] == 4) { $has_visual_alternative = true; } } } // append/replace target alternative to <img ... src="source" ...></a> if (!$processed && preg_match("/\\<img.*src=\"" . preg_quote($row['resource'], "/") . "\".*\\/\\>/sU", $content)) { $processed = true; if (!$info_only) { $content = preg_replace("/(.*)(\\<img.*src=\"" . preg_quote($row['resource'], "/") . "\".*\\/\\>)(.*)/sU", $pattern_replace_to, $content); } else { if ($row['secondary_type'] == 1) { $has_audio_alternative = true; } if ($row['secondary_type'] == 2) { $has_sign_lang_alternative = true; } if ($row['secondary_type'] == 3) { $has_text_alternative = true; } if ($row['secondary_type'] == 4) { $has_visual_alternative = true; } } } // append/replace target alternative to <object ... source ...></object> if (!$processed && preg_match("/\\<object.*" . preg_quote($row['resource'], "/") . ".*\\<\\/object\\>/sU", $content)) { $processed = true; if (!$info_only) { $content = preg_replace("/(.*)(\\<object.*" . preg_quote($row['resource'], "/") . ".*\\<\\/object\\>)(.*)/sU", $pattern_replace_to, $content); } else { if ($row['secondary_type'] == 1) { $has_audio_alternative = true; } if ($row['secondary_type'] == 2) { $has_sign_lang_alternative = true; } if ($row['secondary_type'] == 3) { $has_text_alternative = true; } if ($row['secondary_type'] == 4) { $has_visual_alternative = true; } } } // append/replace target alternative to <a>...source...</a> or <a ...source...>...</a> // skip this "if" when the source object has been processed in aboved <img> tag if (!$processed && preg_match("/\\<a.*" . preg_quote($row['resource'], "/") . ".*\\<\\/a\\>/sU", $content)) { $processed = true; if (!$info_only) { $content = preg_replace("/(.*)(\\<a.*" . preg_quote($row['resource'], "/") . ".*\\<\\/a\\>)(.*)/sU", $pattern_replace_to, $content); } else { if ($row['secondary_type'] == 1) { $has_audio_alternative = true; } if ($row['secondary_type'] == 2) { $has_sign_lang_alternative = true; } if ($row['secondary_type'] == 3) { $has_text_alternative = true; } if ($row['secondary_type'] == 4) { $has_visual_alternative = true; } } } // append/replace target alternative to <embed ... source ...> if (!$processed && preg_match("/\\<embed.*" . preg_quote($row['resource'], "/") . ".*\\>/sU", $content)) { $processed = true; if (!$info_only) { $content = preg_replace("/(.*)(\\<embed.*" . preg_quote($row['resource'], "/") . ".*\\>)(.*)/sU", $pattern_replace_to, $content); } else { if ($row['secondary_type'] == 1) { $has_audio_alternative = true; } if ($row['secondary_type'] == 2) { $has_sign_lang_alternative = true; } if ($row['secondary_type'] == 3) { $has_text_alternative = true; } if ($row['secondary_type'] == 4) { $has_visual_alternative = true; } } } } } if (!$info_only) { return $content; } else { return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative); } }
/** * displays the founder pulldown * * @param unknown_type $ID * @param unknown_type $selectedVal * @param unknown_type $isBootstrap */ function displayFounderPulldown($ID, $selectedVal, $isBootstrap = false, $tooltip = null) { // include the data access class include_once "DAO.php"; try { // create a new data access object $db = new DAO(); $sql = "EXEC dbo.GetCompanyLookUp @likeClause=" . $like . "'"; // set the select statement $db->setSQL($sql); // execute the SQL if ($db->execute()) { // did we get some rows if (sqlsrv_has_rows($db->getResultSet())) { if ($isBootstrap) { // start the pulldown control echo '<select name="' . $ID . '" id="' . $ID . '" class="form-control" data-toggle="tooltip" data-placement="bottom"' . ' title="' . $tooltip . '"><option value="-1">Select a value...</option>'; // output the table rows while ($row = sqlsrv_fetch_array($db->getResultSet(), SQLSRV_FETCH_ASSOC)) { echo '<option value = "' . $row['CompanyID'] . '" ' . IsSelected($row['CompanyID'], $selectedVal) . '>' . $row['CompanyName'] . '</option>'; } // finish off the control echo "</select>"; } else { // start the pulldown control echo '<select name="' . $ID . '" id="' . $ID . '"><option value="-1">Select a value...</option>'; // output the table rows while ($row = sqlsrv_fetch_array($db->getResultSet(), SQLSRV_FETCH_ASSOC)) { echo '<option value = "' . $row['CompanyID'] . '" ' . IsSelected($row['CompanyID'], $selectedVal) . '>' . $row['CompanyName'] . '</option>'; } // finish off the control echo "</select>"; } } else { echo '<div class="err">No data found.</div>'; } } } catch (Exception $e) { echo $e->getMessage(), "\n"; } }
function queryFromFile($sql_file_path, $table_prefix) { global $db, $progress, $errors; include_once AC_INCLUDE_PATH . 'classes/DAO/DAO.class.php'; $dao = new DAO(); $tables = array(); if (!file_exists($sql_file_path)) { return false; } $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path))); SqlUtility::splitSqlFile($pieces, $sql_query); foreach ($pieces as $piece) { $piece = trim($piece); // [0] contains the prefixed query // [4] contains unprefixed table name if ($table_prefix || $table_prefix == '') { $prefixed_query = SqlUtility::prefixQuery($piece, $table_prefix); } else { $prefixed_query = $piece; } if ($prefixed_query != false) { $table = $table_prefix . $prefixed_query[4]; $prefixed_query[1] = strtoupper($prefixed_query[1]); if (strtoupper($prefixed_query[1]) == 'CREATE TABLE') { if ($dao->execute($prefixed_query[0]) !== false) { $progress[] = 'Table <b>' . $table . '</b> created successfully.'; } else { if (mysql_errno($db) == 1050) { $progress[] = 'Table <b>' . $table . '</b> already exists. Skipping.'; } else { $errors[] = 'Table <b>' . $table . '</b> creation failed.'; } } } elseif ($prefixed_query[1] == 'INSERT INTO' || $prefixed_query[1] == 'ALTER TABLE' || $prefixed_query[1] == 'DROP TABLE' || $prefixed_query[1] == 'UPDATE') { $dao->execute($prefixed_query[0]); } } } return TRUE; }
*/ define('TR_INCLUDE_PATH', '../../include/'); require_once TR_INCLUDE_PATH . 'vitals.inc.php'; $pid = intval($_POST['pid']); $type_id = intval($_POST['a_type']); $secondary_resource = trim($_POST['alternative']); // check post vars if ($pid == 0 || $type_id == 0 || $secondary_resource == '') { exit; } require_once TR_INCLUDE_PATH . 'classes/DAO/DAO.class.php'; $dao = new DAO(); // delete the existing alternative for this (pid, a_type) $sql = "SELECT sr.secondary_resource_id \n FROM " . TABLE_PREFIX . "secondary_resources sr, " . TABLE_PREFIX . "secondary_resources_types srt\n WHERE sr.secondary_resource_id = srt.secondary_resource_id\n AND sr.primary_resource_id = " . $pid . "\n AND sr.language_code = '" . $_SESSION['lang'] . "'\n AND srt.type_id=" . $type_id; //$existing_secondary_result = mysql_query($sql, $db); $existing_secondary_rows = $dao->execute($sql); if (is_array($existing_secondary_rows)) { foreach ($existing_secondary_rows as $existing_secondary) { $sql = "DELETE FROM " . TABLE_PREFIX . "secondary_resources \n\t\t WHERE secondary_resource_id = " . $existing_secondary['secondary_resource_id']; $dao->execute($sql); $sql = "DELETE FROM " . TABLE_PREFIX . "secondary_resources_types \n\t\t WHERE secondary_resource_id = " . $existing_secondary['secondary_resource_id'] . "\n\t\t AND type_id=" . $type_id; $dao->execute($sql); } } // insert new alternative $sql = "INSERT INTO " . TABLE_PREFIX . "secondary_resources (primary_resource_id, secondary_resource, language_code)\n VALUES (" . $pid . ", '" . mysql_real_escape_string($secondary_resource) . "', '" . $_SESSION['lang'] . "')"; $dao->execute($sql); $secondary_resource_id = mysql_insert_id(); $sql = "INSERT INTO " . TABLE_PREFIX . "secondary_resources_types (secondary_resource_id, type_id)\n VALUES (" . $secondary_resource_id . ", " . $type_id . ")"; $dao->execute($sql); exit;
$sql .= "((U.first_name LIKE '{$term}') OR (U.last_name LIKE '{$term}') OR (U.email LIKE '{$term}') OR (U.login LIKE '{$term}')) {$predicate}"; } } $sql = '(' . substr($sql, 0, -strlen($predicate)) . ')'; $search = $sql; } else { $search = '1'; } if ($_GET['user_group_id'] && $_GET['user_group_id'] != -1) { $user_group_sql = "U.user_group_id = " . $_GET['user_group_id']; $page_string .= htmlspecialchars(SEP) . 'user_group_id=' . urlencode($_GET['user_group_id']); } else { $user_group_sql = '1'; } $sql = "SELECT COUNT(user_id) AS cnt FROM " . TABLE_PREFIX . "users U WHERE status {$status} AND {$search} AND {$user_group_sql}"; $rows = $dao->execute($sql); $num_results = $rows[0]['cnt']; $num_pages = max(ceil($num_results / $results_per_page), 1); $page = intval($_GET['p']); if (!$page) { $page = 1; } $count = ($page - 1) * $results_per_page + 1; $offset = ($page - 1) * $results_per_page; if (isset($_GET['apply_all']) && $_GET['change_status'] >= -1) { $offset = 0; $results_per_page = 999999; } $sql = "SELECT U.user_id, U.login, U.first_name, U.last_name, UG.title user_group, U.email, U.status, U.last_login AS last_login \r\n FROM " . TABLE_PREFIX . "users U, " . TABLE_PREFIX . "user_groups UG\r\n WHERE U.user_group_id = UG.user_group_id\r\n AND U.status {$status} AND {$search} AND {$user_group_sql} ORDER BY {$col} {$order} LIMIT {$offset}, {$results_per_page}"; $user_rows = $dao->execute($sql); if (isset($_GET['apply_all']) && $_GET['change_status'] >= -1) {
function importQTI($_POST) { require_once TR_INCLUDE_PATH . 'classes/DAO/DAO.class.php'; require_once TR_INCLUDE_PATH . 'classes/Utility.class.php'; global $msg, $db, $_course_id; // $_POST = $this->_POST; if ($_POST['question'] == '') { $msg->addError(array('EMPTY_FIELDS', _AT('question'))); } //Multiple answer can have 0+ answers, in the QTIImport.class, if size(answer) < 2, answer will be came a scalar. //The following code will change $_POST[answer] back to a vector. $_POST['answer'] = $_POST['answers']; if (!$msg->containsErrors()) { $choice_new = array(); // stores the non-blank choices $answer_new = array(); // stores the associated "answer" for the choices foreach ($_POST['choice'] as $choiceNum => $choiceOpt) { $choiceOpt = Utility::validateLength($choiceOpt, 255); $choiceOpt = trim($choiceOpt); $_POST['answer'][$choiceNum] = intval($_POST['answer'][$choiceNum]); if ($choiceOpt == '') { /* an empty option can't be correct */ $_POST['answer'][$choiceNum] = 0; } else { /* filter out empty choices/ remove gaps */ $choice_new[] = $choiceOpt; if (in_array($choiceNum, $_POST['answer'])) { $answer_new[] = 1; } else { $answer_new[] = 0; } if ($_POST['answer'][$choiceNum] != 0) { $has_answer = TRUE; } } } if ($has_answer != TRUE) { $hidden_vars['required'] = htmlspecialchars($_POST['required']); $hidden_vars['feedback'] = htmlspecialchars($_POST['feedback']); $hidden_vars['question'] = htmlspecialchars($_POST['question']); $hidden_vars['category_id'] = htmlspecialchars($_POST['category_id']); for ($i = 0; $i < count($choice_new); $i++) { $hidden_vars['answer[' . $i . ']'] = htmlspecialchars($answer_new[$i]); $hidden_vars['choice[' . $i . ']'] = htmlspecialchars($choice_new[$i]); } $msg->addConfirm('NO_ANSWER', $hidden_vars); } else { //add slahes throughout - does that fix it? $_POST['answer'] = $answer_new; $_POST['choice'] = $choice_new; $_POST['answer'] = array_pad($_POST['answer'], 10, 0); $_POST['choice'] = array_pad($_POST['choice'], 10, ''); // $_POST['feedback'] = $addslashes($_POST['feedback']); // $_POST['question'] = $addslashes($_POST['question']); $sql_params = array($_POST['category_id'], $_course_id, $_POST['feedback'], $_POST['question'], $_POST['choice'][0], $_POST['choice'][1], $_POST['choice'][2], $_POST['choice'][3], $_POST['choice'][4], $_POST['choice'][5], $_POST['choice'][6], $_POST['choice'][7], $_POST['choice'][8], $_POST['choice'][9], $_POST['answer'][0], $_POST['answer'][1], $_POST['answer'][2], $_POST['answer'][3], $_POST['answer'][4], $_POST['answer'][5], $_POST['answer'][6], $_POST['answer'][7], $_POST['answer'][8], $_POST['answer'][9]); $sql = vsprintf(TR_SQL_QUESTION_MULTIANSWER, $sql_params); // $result = mysql_query($sql, $db); // if ($result==true){ $dao = new DAO(); if ($dao->execute($sql)) { return mysql_insert_id(); } } } }
<?php include_once "DAO.php"; //create a data access object $dao = new DAO(); //pass the sql statement to the data access object $dao->setSQL("[dbo].[getcompanies]"); try { // run the sql statement $dao->execute(); if (sqlsrv_has_rows($dao->getResultSet())) { $rows = sqlsrv_num_rows($dao->getResultSet()); if ($rows === false) { echo "error"; } else { echo 'Number of rows: ' . $rows; } } else { echo "no rows"; } } catch (Exception $e) { return array(false, "NonQuery Error: " . $e->getMessage() . ". SQL: " . $sql); }
echo ' <th rowspan="2" id="header2">' . _AT('resource_type') . '</th>' . "\n"; echo ' <th colspan="4">' . _AT('alternatives') . '</th>' . "\n"; echo ' </tr>' . "\n"; echo ' <tr>' . "\n"; echo ' <th id="header3">' . _AT('text') . '</th>' . "\n"; echo ' <th id="header4">' . _AT('audio') . '</th>' . "\n"; echo ' <th id="header5">' . _AT('visual') . '</th>' . "\n"; echo ' <th id="header6">' . _AT('sign_lang') . '</th>' . "\n"; echo ' </tr>' . "\n"; echo ' </thead>' . "\n"; echo ' <tbody>'; foreach ($primary_resources as $primary_resource_id => $primary_resource_row) { $primary_resource = $primary_resource_row['resource']; $sql = "SELECT prt.type_id, rt.type\n\t\t\t FROM " . TABLE_PREFIX . "primary_resources pr, " . TABLE_PREFIX . "primary_resources_types prt, " . TABLE_PREFIX . "resource_types rt\n\t\t\t WHERE pr.content_id = " . $cid . "\n\t\t\t AND pr.language_code = '" . $_SESSION['lang'] . "'\n\t\t\t AND pr.primary_resource_id='" . $primary_resource_id . "'\n\t\t\t AND pr.primary_resource_id = prt.primary_resource_id\n\t\t\t AND prt.type_id = rt.type_id"; // $primary_type_result = mysql_query($sql, $db); $primary_types = $dao->execute($sql); if (!$is_post_indicator_set) { echo ' <input type="hidden" name="use_post_for_alt" value="1" />' . "\n"; $is_post_indicator_set = true; } // get secondary resources for the current primary resource $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id\n\t\t\t FROM " . TABLE_PREFIX . "primary_resources pr, " . TABLE_PREFIX . "secondary_resources sr, " . TABLE_PREFIX . "secondary_resources_types srt\n\t\t\t WHERE pr.content_id = " . $cid . "\n\t\t\t AND pr.language_code = '" . $_SESSION['lang'] . "'\n\t\t\t AND pr.primary_resource_id='" . $primary_resource_id . "'\n\t\t\t AND pr.primary_resource_id = sr.primary_resource_id\n\t\t\t AND sr.secondary_resource_id = srt.secondary_resource_id"; // $secondary_result = mysql_query($sql, $db); $secondary_resources = $dao->execute($sql); echo ' <tr>' . "\n"; // table cell "original resource" echo ' <td headers="header1">' . "\n"; echo ' <a href="' . $primary_resource . '" title="' . _AT('new_window') . '" target="_new">' . get_display_filename($primary_resource) . '</a>' . "\n"; echo ' </td>' . "\n"; // table cell "original resource type" echo ' <td headers="header2">' . "\n";
// if (!in_array($w, $word)) { // unset($_POST['glossary_defs'][$w]); // continue; // } // echo '<input type="hidden" name="glossary_defs['.$w.']" value="'.htmlspecialchars(stripslashes($d)).'" />'; // } // if (isset($_POST['related_term'])) { // foreach($_POST['related_term'] as $w => $d) { // echo '<input type="hidden" name="related_term['.$w.']" value="'.$d.'" />'; // } // } // } // adapted content $sql = "SELECT pr.primary_resource_id, prt.type_id\n\t FROM " . TABLE_PREFIX . "primary_resources pr, " . TABLE_PREFIX . "primary_resources_types prt\n\t WHERE pr.content_id = " . $cid . "\n\t AND pr.language_code = '" . $_SESSION['lang'] . "'\n\t AND pr.primary_resource_id = prt.primary_resource_id"; // $all_types_result = mysql_query($sql, $db); $types = $dao->execute($sql); $i = 0; if (is_array($types)) { foreach ($types as $type) { $row_alternatives['alt_' . $type['primary_resource_id'] . '_' . $type['type_id']] = 1; } } if ($current_tab != 2 && isset($_POST['use_post_for_alt'])) { echo '<input type="hidden" name="use_post_for_alt" value="1" />'; if (is_array($_POST)) { foreach ($_POST as $alt_id => $alt_value) { if (substr($alt_id, 0, 4) == 'alt_') { echo '<input type="hidden" name="' . $alt_id . '" value="' . $alt_value . '" />'; } } }
/** * Gets the list of IDs and roles for the user. * * @param string $UserName */ function getUserIDRoles($UserName) { // include the data access class include_once "DAO.php"; // preset the return flag $retVal = 0; try { // save the user name in this object $this->setUserName($UserName); // create a new data access object $db = new DAO(); // clear the output variable before use unset($this->UserIDRoleList); // set the stored proc that does the work $db->setSQL("exec dbo.GetUserIDRoles @UserName=N'" . $UserName . "'"); // execute the SQL if ($db->execute()) { // for each item in the table while ($item = sqlsrv_fetch_array($db->getResultSet(), SQLSRV_FETCH_NUMERIC)) { // save the records for this table $this->UserIDRoleList[] = $item; } } } catch (Exception $e) { echo $e->getMessage(), "\n"; // set an error code $retVal = 1; } // return to the caller return $retVal; }
} $str_existing_checks = substr($str_existing_checks, 0, -1); } if ($condition != '') { $condition .= ' AND'; } $condition .= " open_to_public=1"; if ($str_existing_checks != '') { $condition .= " AND check_id NOT IN (" . $str_existing_checks . ")"; } } if ($condition == '') { $condition = '1'; } $sql = "SELECT COUNT(check_id) AS cnt FROM " . TABLE_PREFIX . "checks WHERE {$condition}"; $rows = $dao->execute($sql); $num_results = $rows[0]['cnt']; $num_pages = max(ceil($num_results / $results_per_page), 1); $page = intval($_GET['p']); if (!$page) { $page = 1; } $count = ($page - 1) * $results_per_page + 1; $offset = ($page - 1) * $results_per_page; if (isset($_GET['apply_all']) && $_GET['change_status'] >= -1) { $offset = 0; $results_per_page = 999999; } $checksDAO = new ChecksDAO(); $sql = "SELECT * \r\n FROM " . TABLE_PREFIX . "checks\r\n WHERE {$condition} ORDER BY {$col} {$order} LIMIT {$offset}, {$results_per_page}"; $check_rows = $dao->execute($sql);
/** * gets the participant variants from NCGENES * * @param string $DonorCode */ function doGetParticipantVariants($DonorCode) { // include the data access class include_once "DAO.php"; // create a new data access object $db = new DAO(); // set the request params $AnalysisType = 2; // the type of analysis results (Dx=2 vs. incidental=1) $roleID = 22; // the role of the user (22 is admin/everything) $type = 1; // the type of results (parent rows=1 vs transcript rows=2) $geneID = 'No filter'; // filter on a specific gene in the results $FilterID = -1; // the type of specific bin analysis result (specific Dx code vs. specific incidental code) // create the SQL $sql = "EXEC dbo.GetAnalysisResults @DONOR_CODE = '" . $DonorCode . "', @AnalysisType=" . $AnalysisType . ", @Role=" . $roleID . ", @type=" . $type . ", @geneID='" . $geneID . "', @FilterID=" . $FilterID; // assign the SQL $db->setSQL($sql); // preset the return value $retVal = NULL; // execute the SQL if ($db->execute()) { // did we get some rows if (sqlsrv_has_rows($db->getResultSet())) { // init a counter $i = 0; // output the table rows while ($row = sqlsrv_fetch_array($db->getResultSet(), SQLSRV_FETCH_ASSOC)) { // add the row to the output array $data[$i] = $row; // next row $i++; } // return the data JSON formatted $retVal = '{"data":' . json_encode($data) . '}'; } else { $retVal = '{"error": "doGetParticipantVariants() - No data"}'; } } else { $retVal = '{"error": "doGetParticipantVariants() - Error getting data"}'; } //error_log(print_r($data, true)); // return the data to the caller echo $retVal; // terminate the data stream die; }