Пример #1
0
    /**
     * Persist the object to the database
     * @return boolean Success or failure of the save operation
     * @throws ValidationException
     */
    public function save($clear_checkout = true)
    {
        $success = false;
        if ($this->_logger == null) {
            $this->_logger = new Logger($this->_mysqli);
        }
        $valid = $this->validate();
        if ($valid === true) {
            // Clear any existing checkout
            if ($clear_checkout) {
                $this->checkout_author_id = null;
                $this->checkout_time = null;
            }
            // Make sure plain versions of scenario and leadin are up to date
            $this->get_scenario_plain();
            $this->get_leadin_plain();
            $this->serialize_settings();
            if ($this->bloom == '') {
                $this->bloom = null;
            }
            // If $id is -1 we're inserting a new record
            if ($this->id == -1) {
                $this->created = date('Y-m-d H:i:s');
                $this->last_edited = date('Y-m-d H:i:s');
                $server_ipaddress = str_replace('.', '', NetworkUtils::get_server_address());
                $this->guid = $server_ipaddress . uniqid('', true);
                $params = array_merge(array('ssssssssssssssissssisssssss'), $this->_data);
                $query = <<<QUERY
INSERT INTO questions (q_type, theme, scenario, scenario_plain, leadin, leadin_plain, notes, correct_fback, incorrect_fback, score_method,
display_method, q_option_order, std, bloom, ownerID, q_media, q_media_width, q_media_height, checkout_time, checkout_authorID,
creation_date, last_edited, locked, deleted, status, settings, guid)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
QUERY;
            } else {
                // Otherwise we're updating an existing one
                $params = array_merge(array('ssssssssssssssissssisssssssi'), $this->_data, array(&$this->id));
                $this->last_edited = date('Y-m-d H:i:s');
                $query = <<<QUERY
UPDATE questions
SET q_type = ?, theme = ?, scenario = ?, scenario_plain = ?, leadin = ?, leadin_plain = ?, notes = ?, correct_fback = ?, incorrect_fback = ?,
score_method = ?, display_method = ?, q_option_order = ?, std = ?, bloom = ?, ownerID = ?, q_media = ?, q_media_width = ?, q_media_height = ?,
checkout_time = ?, checkout_authorID = ?, creation_date = ?, last_edited = ?, locked = ?, deleted = ?, status = ?, settings = ?, guid = ?
WHERE q_id = ?
QUERY;
            }
            $result = $this->_mysqli->prepare($query);
            call_user_func_array(array($result, 'bind_param'), $params);
            $result->execute();
            $success = $result->affected_rows > -1;
            if ($this->_mysqli->error) {
                try {
                    throw new Exception("MySQL error " . $this->_mysqli->error . "<br /> Query:<br /> {$query}", $this->_mysqli->errno);
                } catch (Exception $e) {
                    echo "Error No: " . $e->getCode() . " - " . $e->getMessage() . "<br />";
                    echo nl2br($e->getTraceAsString());
                }
            }
            if ($success) {
                if ($this->id == -1) {
                    $this->id = $this->_mysqli->insert_id;
                    $this->_logger->track_change('New Question', $this->id, $this->_user_id, $this->get_leadin(), '', '');
                } else {
                    // Log any changes
                    foreach ($this->_modified_fields as $key => $value) {
                        $db_field = in_array($key, array_keys($this->_field_map)) ? $this->_field_map[$key] : $key;
                        $change_field = in_array($db_field, array_keys($this->_change_field_map)) ? $this->_change_field_map[$db_field] : $db_field;
                        // Exception for media as it returns an array. Need better solution if other properties do the same in the future
                        $get_method = 'get_' . $key . ($key == 'media' ? '_filename' : '');
                        if ($value['message'] == '') {
                            $this->_logger->track_change($this->_lang_strings['editquestion'], $this->id, $this->_user_id, $value['value'], $this->{$get_method}(), $change_field);
                        } else {
                            $this->_logger->track_change($value['message'], $this->id, $this->_user_id, $value['value'], $this->{$get_method}(), $change_field);
                        }
                    }
                }
            }
            $result->close();
            if ($success) {
                // Updates the teams/question modules
                QuestionUtils::update_modules($this->teams, $this->id, $this->_mysqli, $this->_userObj);
            }
            if ($success) {
                $success = $this->save_options();
            }
            $this->_modified_fields = array();
        } else {
            throw new ValidationException($valid);
        }
        return $success;
    }
Пример #2
0
     }
 } else {
     $new_o_media = '';
 }
 if ($marks_correct == '') {
     $marks_correct = 1;
 }
 if ($line == 0) {
     // First record - write out the question, all the rest are options.
     $bloom = empty($bloom) ? NULL : $bloom;
     if ($status_array[$status]->get_retired()) {
         $new_status = $default_status;
     } else {
         $new_status = $status;
     }
     $server_ipaddress = str_replace('.', '', NetworkUtils::get_server_address());
     $guid = $server_ipaddress . uniqid('', true);
     $addQuestion = $mysqli->prepare("INSERT INTO questions (q_id, q_type, theme, scenario, leadin, correct_fback, incorrect_fback, display_method, notes, ownerID, q_media, q_media_width, q_media_height, creation_date, last_edited, bloom, scenario_plain, leadin_plain, checkout_time, checkout_authorID, deleted, locked, std, status, q_option_order, score_method, settings, guid) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?, NULL, NULL, NULL, NULL, ?, ?, ?, ?, ?, ?)");
     if ($mysqli->error) {
         try {
             throw new Exception("MySQL error {$mysqli->error} <br /> Query:<br /> ", $mysqli->errno);
         } catch (Exception $e) {
             echo "Error No: " . $e->getCode() . " - " . $e->getMessage() . "<br />";
             echo nl2br($e->getTraceAsString());
         }
     }
     $addQuestion->bind_param('ssssssssisssssssissss', $q_type, $theme, $scenario, $leadin, $correct_fback, $incorrect_fback, $display_method, $notes, $userObject->get_user_ID(), $new_q_media, $q_media_width, $q_media_height, $bloom, $scenario_plain, $leadin_plain, $std, $new_status, $q_option_order, $score_method, $settings, $guid);
     $addQuestion->execute();
     $new_qids[] = $question_id = $mysqli->insert_id;
     if ($q_type == 'enhancedcalc') {
         $calculation_qid_map[$q_id] = $question_id;
Пример #3
0
                $speed = str_replace(')', '', $speed_parts[1]);
            }
        }
    }
    if (isset($processor_parts[0])) {
        echo "<tr><td>" . $string['processor'] . "</td><td>" . $processor_parts[0] . "({$speed})</td></tr>\n";
        echo "<tr><td>" . $string['cpus'] . "</td><td>{$physical} ({$virtual} virtual)</td></tr>\n";
    }
} else {
    $results = shell_exec('wmic cpu get name');
    $lines = explode('<br />', nl2br($results));
    echo "<tr><td>" . $string['processor'] . "</td><td>" . $lines[1] . "</td></tr>\n";
}
echo "<tr><td style=\"width:90px\">" . $string['servername'] . "</td><td>" . gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME'])) . "</td></tr>\n";
echo "<tr><td>" . $string['hostname'] . "</td><td>" . $_SERVER['HTTP_HOST'] . "</td></tr>\n";
echo "<tr><td>" . $string['ipaddress'] . "</td><td>" . NetworkUtils::get_server_address() . "</td></tr>\n";
echo "<tr><td>" . $string['clock'] . "</td><td>" . date('d F Y H:i:s') . "</td></tr>\n";
echo "<tr><td>" . $string['os'] . "</td><td>" . php_uname('s') . "</td></tr>\n";
echo "<tr><td>" . $string['webserver'] . "</td><td>" . $_SERVER['SERVER_SOFTWARE'] . "</td></tr>\n";
echo "<tr><td>" . $string['php'] . "</td><td>" . phpversion() . "</td></tr>\n";
echo "<tr><td>" . $string['mysql'] . "</td><td>" . $mysqli->server_info . "</td></tr>\n";
echo '<tr><td colspan="2">&nbsp;</td></tr>';
echo '<tr><td colspan="2" class="sechead">' . $string['clientcomputer'] . '</td></tr>';
echo '<tr><td>' . $string['ipaddress'] . '</td><td>' . NetworkUtils::get_client_address() . '</td></tr>';
echo '<tr><td>' . $string['clock'] . '</td><td><script>the_date = new Date(); document.write(the_date.toLocaleString("' . $language . '")); </script></td></tr>';
echo '<tr><td>' . $string['browser'] . '</td><td>' . $_SERVER['HTTP_USER_AGENT'] . '</td></tr>';
echo '<tr><td colspan="2">&nbsp;</td></tr>';
echo '<tr><td colspan="2" class="sechead">' . $string['partitions'] . '</td></tr>';
echo '<tr><td colspan="2" rowspan="18" valign="top" align="left"><table cellspacing="0" cellpadding="2" border="0" style="font-size:90%">';
if (php_uname('s') == 'Windows NT') {
    $disks = array('A:\\', 'B:\\', 'C:\\', 'D:\\', 'E:\\', 'F:\\', 'G:\\', 'H:\\', 'I:\\', 'J:\\', 'K:\\', 'L:\\', 'M:\\', 'N:\\', 'O:\\', 'P:\\', 'Q:\\', 'R:\\', 'S:\\', 'T:\\', 'U:\\', 'V:\\', 'W:\\', 'X:\\', 'Y:\\', 'Z:\\');
Пример #4
0
 /**
  * IMPORT: Insert a single question into the database.
  * @param array $q - Array holding all the information to create the question.
  */
 private function write_question($q)
 {
     // Stop SQL errors with ENUM fields and old data which may be blank.
     if ($q['bloom'] == '') {
         $q['bloom'] = null;
     }
     if ($q['q_option_order'] == '') {
         $q['q_option_order'] = 'display order';
     }
     if ($q['score_method'] == '') {
         $q['score_method'] = 'Mark per Option';
     }
     $server_ipaddress = str_replace('.', '', NetworkUtils::get_server_address());
     $guid = $server_ipaddress . uniqid('', true);
     $status_string = $q['status'];
     if (isset($this->status_array[$status_string])) {
         $q['status'] = $this->status_array[$status_string]->id;
         // Translate a name into a number
     } else {
         $defaultID = $this->get_default_statusID();
         if ($defaultID !== false) {
             $q['status'] = $defaultID;
         } else {
             $q['status'] = 1;
             // Can't find a valid default, hardwire onto 1.
         }
     }
     $result = $this->db->prepare("INSERT INTO questions VALUE (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?, NULL, NULL, NULL, NULL, ?, ?, ?, ?, ?, ?)");
     $result->bind_param('ssssssssisssssssissss', $q['q_type'], $q['theme'], $q['scenario'], $q['leadin'], $q['correct_fback'], $q['incorrect_fback'], $q['display_method'], $q['notes'], $this->userID, $q['q_media'], $q['q_media_width'], $q['q_media_height'], $q['bloom'], $q['scenario_plain'], $q['leadin_plain'], $q['std'], $q['status'], $q['q_option_order'], $q['score_method'], $q['settings'], $guid);
     $result->execute();
     $q_id = $this->db->insert_id;
     $result->close();
     $date_format = $this->configObj->get('cfg_long_date_php') . ' ' . $this->configObj->get('cfg_short_time_php');
     if ($this->raf_company == $this->configObj->get('cfg_company')) {
         // The import file company is the same as the current installation. Use the same IDs.
         $old_q_id = $this->getQID_GUID($q['guid']);
         if ($old_q_id !== false) {
             $this->logger->track_change('Paper', $q_id, $this->userID, $old_q_id, $q_id, 'Add Question (from RAF)');
             // Log as a copied file
         }
     } else {
         $this->logger->track_change('Paper', $q_id, $this->userID, '', $q_id, 'Add Question (from RAF)');
         // Log as a new file that has been imported
     }
     return $q_id;
 }