function show_question($question, $alternative, $image)
{
    //steg 1: komplettera denna funktion så att den visar ett formulär med en fråga
    shuffle_assoc($alternative);
    foreach ($alternative as $onevalue => $onealternative) {
        //lägg till kod för radiobuttons här
    }
}
/**
 * Preprocess checkbox options
 *
 * @param array				Checkbox options
 * @return array			Checkbox options
 */
function vwm_checkboxes_preprocess($options)
{
    // If the options are to be displayed randomally
    if ($options['order'] == 'random') {
        $options['checkboxes'] = shuffle_assoc($options['checkboxes']);
    }
    return $options;
}
/**
 * Preprocess radio matrix options
 *
 * @param array				Radio matrix options
 * @return array			Radio matrix options
 */
function vwm_radio_matrix_preprocess($options)
{
    // If the x options are to be displayed randomally
    if ($options['x_order'] === 'random') {
        $options['x'] = shuffle_assoc($options['x']);
    }
    // If the y options are to be displayed randomally
    if ($options['y_order'] === 'random') {
        $options['y'] = shuffle_assoc($options['y']);
    }
    return $options;
}
 public function testShuffleAssoc()
 {
     $this->assertEquals('string', shuffle_assoc('string'));
     $expected = ['x' => 'x', 'y' => 'y', 'z' => 'z'];
     $shuffled = shuffle_assoc($expected);
     $this->assertFalse((bool) array_diff_assoc($expected, $shuffled));
     $this->assertFalse((bool) array_diff_assoc($shuffled, $expected));
     srand(40);
     $expected = ['z' => 'z', 'y' => 'y', 'x' => 'x'];
     $shuffled = shuffle_assoc($expected);
     $this->assertEquals(json_encode($expected), json_encode($shuffled));
 }
Example #5
0
function createDeck()
{
    $suits = array("clubs", "diamonds", "hearts", "spades");
    $faces = array("Ace" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5, "6" => 6, "7" => 7, "8" => 8, "9" => 9, "10" => 10, "Jack" => 10, "Queen" => 10, "King" => 10);
    $deck = array();
    foreach ($faces as $key => $face) {
        foreach ($suits as $suit) {
            $newKey = "{$key} of {$suit}";
            $deck[$newKey] = $face;
        }
    }
    shuffle_assoc($deck);
    return $deck;
}
Example #6
0
	$t = Title::makeTitle($row->page_namespace, $row->page_title);
	if (!$t) continue;
	$titles[] = $t;
}
*/
#echo sizeof($titles); exit;
$index = 0;
$old = wfTimestamp(TS_MW, time() - 60 * 60);
foreach ($titles as $t) {
    $recentedits = $dbr->selectField('recentchanges', array('count(*)'), array('rc_cur_id' => $t->getArticleID(), 'rc_user_text' => $username, "rc_timestamp > '{$old}'"));
    if ($recentedits > 0) {
        echo "{$t->getText()} was recently edited, skipping.\n";
        continue;
    }
    $r = Revision::newFromTitle($t);
    $kw = shuffle_assoc($kw);
    if (!$r) {
        continue;
    }
    $text = $r->getText();
    $parts = preg_split("@(\\[\\[[^\\]]*\\]\\]|\\{\\{[^\\}]*\\}\\}|\\[[^\\]]*])@", $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    $changed = false;
    $onthispage = 0;
    $newtext = $text;
    $thisround = array();
    foreach ($parts as $p) {
        $newp = $p;
        foreach ($kw as $w => $dest) {
            if (isset($thisround[$w])) {
                break;
            }
require 'class.roundrobin.php';
function shuffle_assoc(&$array)
{
    $keys = array_keys($array);
    shuffle($keys);
    foreach ($keys as $key) {
        $new[$key] = $array[$key];
    }
    $array = $new;
    echo 'shuffle_assoc<pre>', print_r($array, true), '</pre><br>';
    return true;
}
// Let's see how 7 of the best british football teams fight against each other
$teams = array('Banbury United', 'Bashley', 'Bedford Town', 'Brackley Town', 'Cambridge City', 'Chippenham Town', 'Clevedon Town');
shuffle_assoc($teams);
$roundrobin = new roundrobin($teams);
// Generated matches with matchdays and free tickets - because we have an uneven number of teams
echo "<h3>Generated matches with matchdays and free tickets</h3><br />";
$roundrobin->free_ticket_identifer = "FREE TICKET";
//default is "free ticket"
$roundrobin->create_matches();
// Did everything went right?
if ($roundrobin->finished) {
    $i = 1;
    //Ok, iterating over the matchdays...
    while ($roundrobin->next_matchday()) {
        echo "-------Matchday " . $i . "-------<br />";
        //...and the matches of one match day
        while ($match = $roundrobin->next_match()) {
            echo $match[0] . "  <b>vs</b>  " . $match[1] . "<br />";
Example #8
0
    if (!is_array($list)) {
        return $list;
    }
    $keys = array_keys($list);
    shuffle($keys);
    $random = array();
    foreach ($keys as $key) {
        $random[$key] = $list[$key];
    }
    return $random;
}
$randomtrailObj = new trails();
$randomtrails = $randomtrailObj->getRand();
$count = $randomtrails['totalMatched'];
$trails = $randomtrails['trails'];
$trails = shuffle_assoc($trails);
$ids = array_keys($trails);
$trails_master = $trails;
$trails = array_slice($trails_master, 0, 12);
$trails_next = array_slice($trails_master, 12, 6);
$trails_last = array_slice($trails_master, 18, 6);
ob_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
  <title>Prescription Trails - New Mexico</title>
    <meta name="description" content="The New Mexico Prescription Trails web site will help you find some of the best park and trail walking and wheelchair rolling paths in the state!" />
    <!-- Schema.org markup for Google+ -->
Example #9
0
    } else {
        $idnext = 0;
    }
    $data = get_record("apps_dragdrope", array("id" => $idc));
    $score = get_user_score($_SESSION['userid'], 8);
    $c = 0;
    $questions = array();
    for ($i = 1; $i <= 5; $i++) {
        $var = "var" . $i;
        if (!empty($data->{$var})) {
            $questions[$i] = $data->{$var};
        }
    }
    $questions = shuffle_assoc($questions);
    $answers = array();
    for ($i = 1; $i <= 5; $i++) {
        $var = "a" . $i;
        if (!empty($data->{$var})) {
            $answers[$i] = $data->{$var};
        }
    }
    $answers = shuffle_assoc($answers);
    if (isset($_SESSION['currentcourse'])) {
        $course = get_record("course", array("id" => $_SESSION['currentcourse']));
    } else {
        $course = get_record("course", array("id" => $_COOKIE['mcm_course']));
    }
    add_log($_SESSION['userid'], 8, time());
    mobilehtmlheader('DragDrope activity');
    include_once $CFG['dirroot'] . "/apps/dragdrope/" . $appsfolder . "/i.php";
}
Example #10
0
 /**
  * @param Exercise $exercise
  * @param int $course_id
  * @param string $order
  * @param bool $shuffle
  * @param bool $excludeCategoryWithNoQuestions
  * @return array|bool
  */
 public function getCategoryExerciseTree($exercise, $course_id, $order = null, $shuffle = false, $excludeCategoryWithNoQuestions = true)
 {
     if (empty($exercise)) {
         return array();
     }
     if (!$exercise->specialCategoryOrders) {
         return false;
     }
     $course_id = intval($course_id);
     $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
     $categoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
     $sql = "SELECT * FROM {$table} qc\n              \tLEFT JOIN {$categoryTable} c\n                ON (qc.c_id = c.c_id AND c.id = qc.category_id)\n                WHERE qc.c_id = {$course_id} AND exercise_id = {$exercise->id} ";
     if (!empty($order)) {
         $sql .= "ORDER BY {$order}";
     }
     $categories = array();
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             if ($excludeCategoryWithNoQuestions) {
                 if ($row['count_questions'] == 0) {
                     continue;
                 }
             }
             if (empty($row['title']) && empty($row['category_id'])) {
                 $row['title'] = get_lang('NoCategory');
             }
             $categories[$row['category_id']] = $row;
         }
     }
     if ($shuffle) {
         shuffle_assoc($categories);
     }
     return $categories;
 }
Example #11
0
 $result2 = mysql_query("SELECT ID, examen_ID, user_ID, time, pregunta, respuestas, tiempo\r\nFROM " . SQL . "examenes_preg\r\nWHERE examen_ID = '" . $_GET['b'] . "' OR examen_ID = 0\r\nORDER BY examen_ID DESC, RAND() LIMIT " . $r['num_preguntas'], $link);
 echo mysql_error($link);
 while ($r2 = mysql_fetch_array($result2)) {
     $respuestas = '';
     $res2 = '';
     $res = explode("|", $r2['respuestas']);
     $res2['a'] = $res[0];
     $respuestas_correctas[] = md5($res[0]);
     $res2['b'] = $res[1];
     if ($res[2]) {
         $res2['c'] = $res[2];
     }
     if ($res[3]) {
         $res2['d'] = $res[3];
     }
     $res2 = shuffle_assoc($res2);
     $examen_tiempo += $r2['tiempo'];
     foreach ($res2 as $ID => $respuesta) {
         $respuestas .= '<input type="radio" name="respuesta' . $r2['ID'] . '" value="' . md5($respuesta) . '" />' . $respuesta . '<br />';
     }
     if ($pregs) {
         $pregs .= '|';
     }
     $pregs .= $r2['ID'];
     $txt .= '<li><b>&iquest;' . $r2['pregunta'] . '?</b><br />' . $respuestas . '</li>';
 }
 $examen_tiempo += 10;
 $limite_tiempo = time() + $examen_tiempo;
 $_SESSION['examen']['respuestas'] = $respuestas_correctas;
 $_SESSION['examen']['tiempo'] = $limite_tiempo;
 $_SESSION['examen']['ID'] = $_GET['b'];
Example #12
0
shuffle($result);
$body = '';
for ($ex = 0; $ex < TOTAL_EXAMENES_A_GENERAR; $ex++) {
    $num_pregunta = 1;
    $referencia_examen = mb_strtoupper(get_random_string(4, 4, true, false, false));
    if ($ex > 0) {
        $body .= '<div class="newpage"></div>' . PHP_EOL;
    }
    $body .= '<p>Nombre: <span class="referenciaexamen"> COD: ' . $referencia_examen . '</span></p>';
    $soluciones[$referencia_examen] = array();
    foreach ($result as $a => $b) {
        $body .= '<div id="pregunta' . $num_pregunta . '" class="pregunta">';
        $body .= '<h2 class="titulopregunta">' . $num_pregunta . ') ' . $b['titulo'] . '</h2>' . PHP_EOL;
        if ($b['tipo'] == 'TEST') {
            $body .= '<ul class="listarespuestastest">' . PHP_EOL;
            $respuestas_rnd = shuffle_assoc($b['respuestas']);
            $i = 'a';
            foreach ($respuestas_rnd as $c => $d) {
                $body .= '<li class="resupestatest">' . $i . ') ' . $c . '</li>' . PHP_EOL;
                if ($d) {
                    $soluciones[$referencia_examen][$num_pregunta] = $i;
                }
                $i++;
            }
            $body .= '</ul>' . PHP_EOL;
        } elseif ($b['tipo'] == 'DEFINE') {
            $body .= str_repeat("<br />", $b['espacios']);
        }
        $body .= '</div>' . PHP_EOL;
        if ($num_pregunta % PREGUNTAS_POR_PAGINA == 0) {
            $body .= '<div class="newpage"></div>' . PHP_EOL;
function show_japanese()
{
    // try-catchで接続エラーを取得&表示
    try {
        $pdo_object = new PDO('mysql:host=localhost;dbname=Challenge_db;charset=utf8', 'sakamoto', 2591);
    } catch (PDOException $E) {
        die('接続に失敗しました:' . $E->getMessage());
    }
    //SQL文を格納した文字列を定義(今回はレコード指定のSQL文)
    $sql = "select * from movies where movie_type=2";
    //実行とその結果を受け取れる変数を用意
    $query = $pdo_object->prepare($sql);
    //SQLを実行
    $query->execute();
    $youga_query = $query->fetchAll(PDO::FETCH_ASSOC);
    //var_dump($youga_query);
    //配列データをシャッフルさせる
    $result = shuffle_assoc($youga_query);
    $i = 0;
    $view = 3;
    foreach ($result as $value) {
        if ($i >= $view) {
            break;
        } else {
            ?>
  <article>
    <a href="<?php 
            echo $value["FilmUrl"];
            ?>
" target="window"> <img src="<?php 
            echo $value["ImageUrl"];
            ?>
" width="300" height="363"></a>
    <a href="<?php 
            echo $value["FilmUrl"];
            ?>
" target="window"><h2><?php 
            echo $value["FilmTitle"];
            ?>
</h2></a>


  <form action="<?php 
            echo MOVIE_DETAIL;
            ?>
?id=<?php 
            echo $value['FilmID'];
            ?>
" method="POST">
    <input type="hidden" name="FilmTitle" value="<?php 
            echo $value['FilmTitle'];
            ?>
";>
    <input type="hidden" name=" itemCaption" value="<?php 
            echo $value['itemCaption'];
            ?>
";>
    <input type="submit" name="detail" value="作品詳細";>
  </form>

  </article>
  <?php 
            $i++;
        }
    }
    //接続を切断
    $pdo_object = null;
}
Example #14
0
    }
}
/* */
function shuffle_assoc(&$array)
{
    $keys = array_keys($array);
    shuffle($keys);
    foreach ($keys as $key) {
        $new[$key] = $array[$key];
    }
    $array = $new;
    return true;
}
if (isset($_POST['q']) && isset($_POST['maxResults'])) {
    $result = array_merge($videos, $images, $tweetsres);
    shuffle_assoc($result);
    $result = array_slice($result, 0, $_POST['maxResults']);
    $htmlres = '';
    //var_dump($result);
    foreach ($result as $key => $value) {
        $htmlres .= $value;
    }
    $htmlBody .= '<ul>' . $htmlres . '</ul>';
}
?>

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>SearchAll</title>
Example #15
0
function get_baner($W, $H)
{
    global $theme_baners, $all_baners, $used_baners, $script_fname, $ftp_con, $ftp_dir, $tmp;
    global $script_dir, $scripts, $keyword, $randkeyword;
    shuffle_assoc($theme_baners);
    shuffle_assoc($all_baners);
    $key = $W . '_' . $H;
    if (array_key_exists($key, $theme_baners)) {
        $baners = $theme_baners[$key];
        $new_baners = array_diff($baners, $used_baners);
        $new_baners = array_values(array_unique($new_baners));
        shuffle($new_baners);
        if (count($new_baners) > 0) {
            $baner = $new_baners[array_rand($new_baners)];
        } else {
            $baner = $baners[array_rand($baners)];
        }
        unset($baners);
    } else {
        foreach ($theme_baners as $curr_key => $curr_val) {
            $curr_size_arr = explode('_', $curr_key);
            $curr_W = $curr_size_arr['0'];
            if (isset($curr_size_arr['1'])) {
                $curr_H = $curr_size_arr['1'];
            } else {
                echo 'Неправильный формат ключа банера';
                continue;
            }
            if ($curr_W <= $W && $curr_H <= $H) {
                $kandidats[] = $curr_val;
            }
        }
        if (isset($kandidats)) {
            $kandidats = array_diff($kandidats, $used_baners);
            $kandidats = array_values(array_unique($kandidats));
            shuffle($kandidats);
            $baners = $kandidats[array_rand($kandidats)];
            shuffle($baners);
            unset($kandidats);
            $baner = $baners[array_rand($baners)];
            unset($baners);
        } elseif (array_key_exists($key, $all_baners)) {
            $baners = $all_baners[$key];
            $new_baners = array_diff($baners, $used_baners);
            $baners = array_unique($baners);
            shuffle($baners);
            $baner = $baners[array_rand($baners)];
            unset($baners);
            //$baner = str_replace('[SCRIPTNAME]',$b_script_fname,$baner);
            $baner = str_replace('[ANKOR]', $keyword, $baner);
            $baner = str_replace('[RANDKEYWORD]', $randkeyword, $baner);
            return $baner;
            exit;
        } else {
            foreach ($all_baners as $curr_key => $curr_val) {
                $curr_size_arr = explode('_', $curr_key);
                $curr_W = $curr_size_arr['0'];
                $curr_H = $curr_size_arr['1'];
                if ($curr_W <= $W && $curr_H <= $H) {
                    $kandidats[] = $curr_val;
                }
            }
            if (isset($kandidats)) {
                $kandidats = array_diff($kandidats, $used_baners);
                $kandidats = array_values(array_unique($kandidats));
                shuffle($kandidats);
                $baners = $kandidats[array_rand($kandidats)];
                $baners = array_values(array_unique($baners));
                unset($kandidats);
                shuffle($baners);
                $baner = $baners[array_rand($baners)];
                unset($baners);
            } else {
                $baner = '';
            }
        }
    }
    if (!$baner == '') {
        $used_baners[] = $baner;
    }
    $baner_str_arr = explode('|||', $baner);
    if (count($baner_str_arr) > 1) {
        $id_redir = $baner_str_arr[0];
        $baner = $baner_str_arr[1];
    } else {
        $baner = $baner_str_arr[0];
    }
    if (isset($id_redir)) {
        //Получаем редирект
        $result = mysql_query("SELECT `redir_code` FROM `redirects` WHERE `id` = '{$id_redir}'");
        if (!$result) {
            echo mysql_error();
            set_status('dorgen_tasks', $id_task, 'dor_status', 'error');
            exit;
        }
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $redir_code = StripSlashes($row["redir_code"]);
        }
        mysql_free_result($result);
        //Имя файла со скриптом редиректа текущего банера
        $b_script_fname = $id_redir . '_' . $script_fname;
        //Если такой файл еще не существует, то создаем его и вставляем туда редирект
        if (!file_exists($script_dir . "/" . $b_script_fname)) {
            $fh = @fopen($script_dir . "/" . $b_script_fname, 'w+');
            if (!$fh) {
                echo 'Невозможно создать файл со скриптом редиректа для банера';
                continue;
            }
            $fp = @fputs($fh, $redir_code);
            if (!$fp) {
                echo 'Невозможно записать в файл со скриптом редиректа для банера';
                continue;
            }
            fclose($fh);
            //$upload_page = @upload_page_to_host($b_script_fname, $ftp_con, $ftp_dir);
            //if(!$upload_page){
            //    echo 'Невозможно залить со скриптом редиректа для банера на хост';
            //    continue;
            //}
        }
        $baner = str_replace('[SCRIPTNAME]', $b_script_fname, $baner);
        $baner = str_replace('[ANKOR]', $keyword, $baner);
        $baner = str_replace('[RANDKEYWORD]', $randkeyword, $baner);
    }
    return $baner;
    exit;
}
Example #16
0
 public function create_pieform_array_from_xml($values = null, $fieldset = 'tab1')
 {
     $xmlDoc = new DOMDocument('1.0', 'UTF-8');
     // 'title' field in 'artefact' table contains the survey xml filename...
     try {
         $ch = curl_init(get_config('wwwroot') . 'artefact/survey/surveys/' . $this->get('title'));
         # Return http response in string
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $xmlDoc->loadXML(curl_exec($ch));
     } catch (Exception $e) {
         $message = get_string('surveyerror', 'artefact.survey', $this->get('title'));
         $_SESSION['messages'][] = array('type' => 'error', 'msg' => $message);
     }
     $pieform_array = array();
     $pieform_array['name'] = 'questionnaire';
     $pieform_array['renderer'] = get_survey_renderer(get_config('lang'));
     $pieform_array['method'] = 'post';
     $pieform_array['plugintype'] = 'artefact';
     $pieform_array['pluginname'] = 'survey';
     $pieform_array['configdirs'] = array(get_config('libroot') . 'form/', get_config('docroot') . 'artefact/survey/form/');
     $pieform_array['elements'] = array();
     if ($xmlDoc->getElementsByTagName('survey')->item(0) != null) {
         $help_language = $xmlDoc->getElementsByTagName('survey')->item(0)->getAttribute('helpLanguage');
     } else {
         $help_language = '';
     }
     $survey_name = $xmlDoc->getElementsByTagName('survey')->item(0)->getAttribute('name');
     $required_responses = return_bool($xmlDoc->getElementsByTagName('survey')->item(0)->getAttribute('requiredResponses'));
     $question_order = $xmlDoc->getElementsByTagName('questions')->item(0)->getAttribute('order');
     $question_order_exists = true;
     if (empty($question_order) || !isset($question_order)) {
         $question_order = null;
         $question_order_exists = false;
     }
     // Read all question IDs from XML survey file
     // and create random order of that IDs (questions)
     // The questions will be printed randomly if sections are joined
     // e.g.: <questions sections="joined" order="random">
     if ($question_order == 'random') {
         $questionIDs = $xmlDoc->getElementsByTagName('question');
         $question_ids = array();
         foreach ($questionIDs as $questionID) {
             array_push($question_ids, $questionID->getAttribute('id'));
         }
         shuffle($question_ids);
         $question_order = implode(',', $question_ids);
     }
     $section_type = $xmlDoc->getElementsByTagName('questions')->item(0)->getAttribute('sections');
     if (empty($section_type) || !isset($section_type)) {
         $section_type = 'separated';
     }
     $show_results = $xmlDoc->getElementsByTagName('results')->item(0);
     if (empty($show_results) || !isset($show_results)) {
         $show_results = false;
     } else {
         $show_results = return_bool($show_results->getAttribute('showResults'));
     }
     $responses = $xmlDoc->getElementsByTagName('response');
     $possible_responses = array();
     foreach ($responses as $response) {
         $children = $response->cloneNode(true);
         $options = $children->getElementsByTagName('option');
         $response_array = array();
         foreach ($options as $option) {
             // Response label
             $optionlabel = $option->getAttribute(get_config('lang'));
             if (empty($optionlabel)) {
                 $optionlabel = $option->getAttribute(self::get_default_lang($this->get('title')));
             }
             // Replace {image:pict.jpg} in responses with proper <img src="pict.jpg"> tag...
             $optionlabel = preg_replace('#{image:([a-zA-Z0-9\\.\\_\\-\\~]+)}#', '<img src="' . get_config('wwwroot') . 'artefact/survey/surveys/' . substr($this->get('title'), 0, -4) . '/$1" style="border:1px solid black">', $optionlabel);
             $optionvalue = $option->getAttribute('value');
             //if (isset($optionvalue) && !empty($optionvalue)) {
             if (isset($optionvalue)) {
                 $response_array = array_merge($response_array, array($optionvalue => $optionlabel));
             } else {
                 $optionsection = $option->getAttribute('section');
                 $optionid = $option->getAttribute('id');
                 //if (isset($optionsection) && !empty($optionsection) && isset($optionid) && !empty($optionid)) {
                 if (isset($optionsection) && isset($optionid)) {
                     $response_array = array_merge($response_array, array($optionsection . '_' . $optionid => $optionlabel));
                 }
             }
         }
         // If set, than shuffle/randomize response order...
         if (return_bool($response->getAttribute('shuffle'))) {
             $response_array = shuffle_assoc($response_array);
         }
         $possible_responses = array_merge($possible_responses, array($response->getAttribute('id') => $response_array));
     }
     //---------------------------
     // Sections are separated...
     //---------------------------
     if ($section_type == 'separated') {
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('section_type' => array('type' => 'hidden', 'value' => $section_type)));
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('show_results' => array('type' => 'hidden', 'value' => $show_results)));
         $sections = $xmlDoc->getElementsByTagName('section');
         foreach ($sections as $section) {
             $question_elements_array = array();
             // Add section help, if it is enabled...
             $section_intro = return_bool($section->getAttribute('help'));
             if ($section_intro) {
                 $introhtml = '<a href="#" onClick="surveyHelp(\'artefact\',\'survey\',\'' . $survey_name . '\',\'section_' . $section->getAttribute('name') . '\',\'' . self::get_default_lang($this->get('title')) . '\',this); return false;">';
                 $introhtml .= '<img src="' . get_config('wwwroot') . 'theme/raw/static/images/icon_help.png" width="16" height="16" alt="Help" title="Help"></a>';
                 $intro_array = array('type' => 'markup', 'value' => $introhtml);
                 $question_elements_array = array_merge($question_elements_array, array('section_' . $section->getAttribute('name') => $intro_array));
             }
             $children = $section->cloneNode(true);
             $questions = $children->getElementsByTagName('question');
             foreach ($questions as $question) {
                 // Get question type
                 $type = $question->getAttribute('type');
                 if (empty($type) || !isset($type)) {
                     $texttype = 'checkbox';
                 }
                 // Get question text type
                 $texttype = $question->getAttribute('textType');
                 if (empty($texttype) || !isset($texttype)) {
                     $texttype = 'label';
                 }
                 // Get label in Mahara site defined language or -
                 // if the translation doesn't exists - in English
                 $labelhtml = $question->getAttribute(get_config('lang'));
                 if (empty($labelhtml)) {
                     $labelhtml = $question->getAttribute(self::get_default_lang($this->get('title')));
                 }
                 // Add help icon with link to help file in primary/secondary language...
                 $help_enabled = return_bool($question->getAttribute('help'));
                 if ($help_enabled) {
                     if ($help_language == 'secondary') {
                         $lang = $this->get('note');
                     } else {
                         $lang = get_config('lang');
                     }
                     $labelhtml .= ' <a href="#" onClick="surveyHelp(\'artefact\',\'survey\',\'' . $survey_name . '\',\'' . $question->getAttribute('id') . '\',\'' . $lang . '\',this); return false;">';
                     $labelhtml .= '<img src="' . get_config('wwwroot') . 'theme/raw/static/images/icon_help.png" width="16" height="16" alt="Help" title="Help"></a>';
                 }
                 // Get description in Survey foreign language or -
                 // if the translation doesn't exists - in English
                 $description = $question->getAttribute($this->get('note'));
                 if (!isset($description) || empty($description)) {
                     $description = $question->getAttribute(self::get_default_lang($this->get('title')));
                 }
                 $question_array = array();
                 $question_array = array_merge($question_array, array('type' => $question->getAttribute('type')));
                 switch ($type) {
                     case 'html':
                         $question_array = array_merge($question_array, array('value' => '&nbsp;'));
                         break;
                     default:
                         $defaultvalue = strval($question->getAttribute('defaultValue'));
                         if (strlen($defaultvalue) == 0) {
                             $name = $question->getAttribute('section');
                             if (!isset($name) || empty($name)) {
                                 $name = $section->getAttribute('name');
                             }
                             $defaultvalue = $values[$name . '_' . $question->getAttribute('id')];
                         }
                         $question_array = array_merge($question_array, array('defaultvalue' => $defaultvalue));
                         break;
                 }
                 if ($texttype == 'title') {
                     $question_array = array_merge($question_array, array('title' => $labelhtml));
                 } else {
                     $question_array = array_merge($question_array, array('labelhtml' => $labelhtml));
                 }
                 if ($this->get('note') != null) {
                     $question_array = array_merge($question_array, array('description' => $description));
                 }
                 // For Pieform elements other than scale or trafficlights, that require options array...
                 $response = $question->getAttribute('response');
                 if (isset($response) && !empty($response) && $type != 'scale' && $type != 'trafficlights') {
                     $question_array = array_merge($question_array, array('options' => $possible_responses[$response]));
                 }
                 // For Pieform element scale (set steps and left/right title or label)
                 if (isset($response) && !empty($response) && $type == 'scale') {
                     // If left label exists...
                     if (isset($possible_responses[$response]['left']) && !empty($possible_responses[$response]['left'])) {
                         $labelleft = $possible_responses[$response]['left'];
                     } else {
                         $labelleft = null;
                     }
                     // If right label exists...
                     if (isset($possible_responses[$response]['right']) && !empty($possible_responses[$response]['right'])) {
                         $labelright = $possible_responses[$response]['right'];
                     } else {
                         $labelright = null;
                     }
                     $question_array = array_merge($question_array, array('titleleft' => $labelleft));
                     $question_array = array_merge($question_array, array('titleright' => $labelright));
                 }
                 // For Pieform element textarea or wysiwyg
                 if ($type == 'textarea' || $type == 'wysiwyg') {
                     $cols = $question->getAttribute('cols');
                     if (!isset($cols) || empty($cols)) {
                         $cols = 60;
                     }
                     $rows = $question->getAttribute('rows');
                     if (!isset($rows) || empty($rows)) {
                         $rows = 6;
                     }
                     $question_array = array_merge($question_array, array('cols' => $cols));
                     $question_array = array_merge($question_array, array('rows' => $rows));
                     $question_array = array_merge($question_array, array('resizable' => false));
                 }
                 $steps = $question->getAttribute('scaleSteps');
                 if (isset($steps) && !empty($steps)) {
                     $question_array = array_merge($question_array, array('steps' => $steps));
                 }
                 $reverse = $question->getAttribute('reverseResponse');
                 if (isset($reverse) && !empty($reverse) && return_bool($reverse) == true) {
                     $question_array = array_merge($question_array, array('reverse' => 'true'));
                 }
                 $br2rows = return_bool($question->getAttribute('br2rows'));
                 $separator = '&nbsp;';
                 if ($type == 'radio' || $type == 'checks') {
                     $separator = '<br>';
                 }
                 if (isset($br2rows) && $br2rows) {
                     $question_array = array_merge($question_array, array('br2rows' => true));
                     $question_array = array_merge($question_array, array('separator' => $separator));
                 }
                 // If answers to all questions are required...
                 if ($required_responses) {
                     $question_array = array_merge($question_array, array('rules' => array('required' => true)));
                 }
                 // Create elements array for questions in each fieldset
                 $name = $question->getAttribute('section');
                 if (!isset($name) || empty($name)) {
                     $name = $section->getAttribute('name');
                 }
                 $question_elements_array = array_merge($question_elements_array, array($name . '_' . $question->getAttribute('id') => $question_array));
                 // If allowed, add wysiwyg/textarea for individual question/response comments...
                 $comments = return_bool($question->getAttribute('allowComments'));
                 if (isset($comments) && $comments) {
                     $comments_array = array();
                     $comments_array = array_merge($comments_array, array('type' => 'wysiwyg', 'rows' => 6, 'cols' => 50, 'title' => get_string('addresponsecomments', 'artefact.survey'), 'defaultvalue' => $values['comment_' . $question->getAttribute('id')]));
                     if (isset($br2rows) && $br2rows) {
                         $comments_array = array_merge($comments_array, array('br2rows' => true));
                     }
                     $question_elements_array = array_merge($question_elements_array, array('comment_' . $question->getAttribute('id') => $comments_array));
                 }
             }
             $legend = $section->getAttribute(self::get_default_lang($this->get('title')));
             if ($section->getAttribute('legend') == 'false' || $section->getAttribute('legend') == '0') {
                 //if (return_bool($section->getAttribute('legend')) == false) {
                 $legend = null;
             }
             $pieform_array['elements'] = array_merge($pieform_array['elements'], array($section->getAttribute('name') => array('type' => 'fieldset', 'legend' => $legend, 'collapsible' => $section->getAttribute('collapsible'), 'collapsed' => $section->getAttribute('collapsed'), 'elements' => $question_elements_array)));
         }
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('submit' => array('type' => 'submit', 'value' => get_string('save'))));
     }
     //------------------------
     // Sections are joined...
     //------------------------
     if ($section_type == 'joined') {
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('section_type' => array('type' => 'hidden', 'value' => $section_type)));
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('show_results' => array('type' => 'hidden', 'value' => $show_results)));
         $question_elements_array = array();
         $sections = $xmlDoc->getElementsByTagName('section');
         foreach ($sections as $section) {
             $children = $section->cloneNode(true);
             $questions = $children->getElementsByTagName('question');
             foreach ($questions as $question) {
                 if ($question_order_exists) {
                     $question_order = str_replace($question->getAttribute('id'), $section->getAttribute('name') . '_' . $question->getAttribute('id'), $question_order);
                 } else {
                     if ($question_order == null) {
                         $question_order .= $section->getAttribute('name') . '_' . $question->getAttribute('id');
                     } else {
                         $question_order .= ',' . $section->getAttribute('name') . '_' . $question->getAttribute('id');
                     }
                 }
                 // Get question type
                 $type = $question->getAttribute('type');
                 if (empty($type) || !isset($type)) {
                     $texttype = 'checkbox';
                 }
                 // Get question text type
                 $texttype = $question->getAttribute('textType');
                 if (empty($texttype) || !isset($texttype)) {
                     $texttype = 'label';
                 }
                 // Get label in Mahara site defined language or -
                 // if the translation doesn't exists - in English
                 $labelhtml = $question->getAttribute(get_config('lang'));
                 if (empty($labelhtml)) {
                     $labelhtml = $question->getAttribute(self::get_default_lang($this->get('title')));
                 }
                 // Add help icon with link to help file in primary/secondary language...
                 $help_enabled = return_bool($question->getAttribute('help'));
                 if ($help_enabled) {
                     if ($help_language == 'secondary') {
                         $lang = $this->get('note');
                     } else {
                         $lang = get_config('lang');
                     }
                     $labelhtml .= ' <a href="#" onClick="surveyHelp(\'artefact\',\'survey\',\'' . $survey_name . '\',\'' . $question->getAttribute('id') . '\',\'' . $lang . '\',this); return false;">';
                     $labelhtml .= '<img src="' . get_config('wwwroot') . 'theme/raw/static/images/icon_help.png" width="16" height="16" alt="Help" title="Help"></a>';
                 }
                 // Get description in Survey foreign language or -
                 // if the translation doesn't exists - in English
                 $description = $question->getAttribute($this->get('note'));
                 if (!isset($description) || empty($description)) {
                     $description = $question->getAttribute(self::get_default_lang($this->get('title')));
                 }
                 $question_array = array();
                 $question_array = array_merge($question_array, array('type' => $question->getAttribute('type')));
                 switch ($type) {
                     case 'html':
                         $question_array = array_merge($question_array, array('value' => '&nbsp;'));
                         break;
                     default:
                         $defaultvalue = strval($question->getAttribute('defaultValue'));
                         if (strlen($defaultvalue) == 0) {
                             $name = $question->getAttribute('section');
                             if (!isset($name) || empty($name)) {
                                 $name = $section->getAttribute('name');
                             }
                             $defaultvalue = $values[$name . '_' . $question->getAttribute('id')];
                         }
                         $question_array = array_merge($question_array, array('defaultvalue' => $defaultvalue));
                         break;
                 }
                 if ($texttype == 'title') {
                     $question_array = array_merge($question_array, array('title' => $labelhtml));
                 } else {
                     $question_array = array_merge($question_array, array('labelhtml' => $labelhtml));
                 }
                 if ($this->get('note') != null) {
                     $question_array = array_merge($question_array, array('description' => $description));
                 }
                 // For Pieform elements other than scale or trafficlights, that require options array...
                 $response = $question->getAttribute('response');
                 if (isset($response) && !empty($response) && $type != 'scale' && $type != 'trafficlights') {
                     $question_array = array_merge($question_array, array('options' => $possible_responses[$response]));
                 }
                 // For Pieform element scale (set steps and left/right title or label)
                 if (isset($response) && !empty($response) && $type == 'scale') {
                     // If left label exists...
                     if (isset($possible_responses[$response]['left']) && !empty($possible_responses[$response]['left'])) {
                         $labelleft = $possible_responses[$response]['left'];
                     } else {
                         $labelleft = null;
                     }
                     // If right label exists...
                     if (isset($possible_responses[$response]['right']) && !empty($possible_responses[$response]['right'])) {
                         $labelright = $possible_responses[$response]['right'];
                     } else {
                         $labelright = null;
                     }
                     $question_array = array_merge($question_array, array('titleleft' => $labelleft));
                     $question_array = array_merge($question_array, array('titleright' => $labelright));
                 }
                 // For Pieform element textarea or wysiwyg
                 if ($type == 'textarea' || $type == 'wysiwyg') {
                     $cols = $question->getAttribute('cols');
                     if (!isset($cols) || empty($cols)) {
                         $cols = 60;
                     }
                     $rows = $question->getAttribute('rows');
                     if (!isset($rows) || empty($rows)) {
                         $rows = 6;
                     }
                     $question_array = array_merge($question_array, array('cols' => $cols));
                     $question_array = array_merge($question_array, array('rows' => $rows));
                     $question_array = array_merge($question_array, array('resizable' => false));
                 }
                 $steps = $question->getAttribute('scaleSteps');
                 if (isset($steps) && !empty($steps)) {
                     $question_array = array_merge($question_array, array('steps' => $steps));
                 }
                 $reverse = $question->getAttribute('reverseResponse');
                 if (isset($reverse) && !empty($reverse) && return_bool($reverse) == true) {
                     $question_array = array_merge($question_array, array('reverse' => 'true'));
                 }
                 $br2rows = return_bool($question->getAttribute('br2rows'));
                 $separator = '&nbsp;';
                 if ($type == 'radio' || $type == 'checks') {
                     $separator = '<br>';
                 }
                 if (isset($br2rows) && $br2rows) {
                     $question_array = array_merge($question_array, array('br2rows' => true));
                     $question_array = array_merge($question_array, array('separator' => $separator));
                 }
                 // If answers to all questions are required...
                 if ($required_responses) {
                     $question_array = array_merge($question_array, array('rules' => array('required' => true)));
                 }
                 // Create elements array for questions in each fieldset
                 $name = $question->getAttribute('section');
                 if (!isset($name) || empty($name)) {
                     $name = $section->getAttribute('name');
                 }
                 $question_elements_array = array_merge($question_elements_array, array($name . '_' . $question->getAttribute('id') => $question_array));
             }
         }
         // Order questions in survey according to order rule, specified in XML file
         $question_elements_ordered = array();
         $items = explode(',', $question_order);
         foreach ($items as $item) {
             $question_elements_ordered = array_merge($question_elements_ordered, array($item => $question_elements_array[$item]));
             // If allowed, add wysiwyg/textarea for individual question/response comments...
             $name = $xmlDoc->getElementsByTagName('section')->item(0)->getAttribute('name');
             $questions = $xmlDoc->getElementsByTagName('question');
             foreach ($questions as $question) {
                 $id = $question->getAttribute('id');
                 $comments = return_bool($question->getAttribute('allowComments'));
                 if ($name . '_' . $id == $item && $comments) {
                     $comments_array = array();
                     $comments_array = array_merge($comments_array, array('type' => 'wysiwyg', 'rows' => 6, 'cols' => 50, 'title' => get_string('addresponsecomments', 'artefact.survey'), 'defaultvalue' => $values['comment_' . $id]));
                     if (isset($br2rows) && $br2rows) {
                         $comments_array = array_merge($comments_array, array('br2rows' => true));
                     }
                     $question_elements_ordered = array_merge($question_elements_ordered, array('comment_' . $id => $comments_array));
                 }
             }
         }
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array($section->getAttribute('name') => array('type' => 'fieldset', 'legend' => null, 'elements' => $question_elements_ordered)));
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('submit' => array('type' => 'submit', 'value' => get_string('save'))));
     }
     //------------------------
     // Sections are tabbed...
     //------------------------
     if ($section_type == 'tabbed') {
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('section_type' => array('type' => 'hidden', 'value' => $section_type)));
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('show_results' => array('type' => 'hidden', 'value' => $show_results)));
         $sections = $xmlDoc->getElementsByTagName('section');
         $i = 1;
         foreach ($sections as $section) {
             $sectiontab = 'tab' . $i;
             $question_elements_array = array();
             $children = $section->cloneNode(true);
             $questions = $children->getElementsByTagName('question');
             foreach ($questions as $question) {
                 // Get question type
                 $type = $question->getAttribute('type');
                 if (empty($type) || !isset($type)) {
                     $texttype = 'checkbox';
                 }
                 // Get question text type
                 $texttype = $question->getAttribute('textType');
                 if (empty($texttype) || !isset($texttype)) {
                     $texttype = 'label';
                 }
                 // Get label in Mahara site defined language or -
                 // if the translation doesn't exists - in English
                 $labelhtml = $question->getAttribute(get_config('lang'));
                 if (empty($labelhtml)) {
                     $labelhtml = $question->getAttribute(self::get_default_lang($this->get('title')));
                 }
                 // Add help icon with link to help file in primary/secondary language...
                 $help_enabled = return_bool($question->getAttribute('help'));
                 if ($help_enabled) {
                     if ($help_language == 'secondary') {
                         $lang = $this->get('note');
                     } else {
                         $lang = get_config('lang');
                     }
                     $labelhtml .= ' <a href="#" onClick="surveyHelp(\'artefact\',\'survey\',\'' . $survey_name . '\',\'' . $question->getAttribute('id') . '\',\'' . $lang . '\',this); return false;">';
                     $labelhtml .= '<img src="' . get_config('wwwroot') . 'theme/raw/static/images/icon_help.png" width="16" height="16" alt="Help" title="Help"></a>';
                 }
                 // Get description in Survey foreign language or -
                 // if the translation doesn't exists - in English
                 $description = $question->getAttribute($this->get('note'));
                 if (!isset($description) || empty($description)) {
                     $description = $question->getAttribute(self::get_default_lang($this->get('title')));
                 }
                 $question_array = array();
                 $question_array = array_merge($question_array, array('type' => $question->getAttribute('type')));
                 switch ($type) {
                     case 'html':
                         $question_array = array_merge($question_array, array('value' => '&nbsp;'));
                         break;
                     default:
                         $defaultvalue = strval($question->getAttribute('defaultValue'));
                         if (strlen($defaultvalue) == 0) {
                             $name = $question->getAttribute('section');
                             if (!isset($name) || empty($name)) {
                                 $name = $section->getAttribute('name');
                             }
                             $defaultvalue = $values[$name . '_' . $question->getAttribute('id')];
                         }
                         $question_array = array_merge($question_array, array('defaultvalue' => $defaultvalue));
                         break;
                 }
                 if ($texttype == 'title') {
                     $question_array = array_merge($question_array, array('title' => $labelhtml));
                 } else {
                     $question_array = array_merge($question_array, array('labelhtml' => $labelhtml));
                 }
                 if ($this->get('note') != null) {
                     $question_array = array_merge($question_array, array('description' => $description));
                 }
                 // For Pieform elements other than scale or trafficlights, that require options array...
                 $response = $question->getAttribute('response');
                 if (isset($response) && !empty($response) && $type != 'scale' && $type != 'trafficlights') {
                     $question_array = array_merge($question_array, array('options' => $possible_responses[$response]));
                 }
                 // For Pieform element scale (set steps and left/right title or label)
                 if (isset($response) && !empty($response) && $type == 'scale') {
                     // If left label exists...
                     if (isset($possible_responses[$response]['left']) && !empty($possible_responses[$response]['left'])) {
                         $labelleft = $possible_responses[$response]['left'];
                     } else {
                         $labelleft = null;
                     }
                     // If right label exists...
                     if (isset($possible_responses[$response]['right']) && !empty($possible_responses[$response]['right'])) {
                         $labelright = $possible_responses[$response]['right'];
                     } else {
                         $labelright = null;
                     }
                     $question_array = array_merge($question_array, array('titleleft' => $labelleft));
                     $question_array = array_merge($question_array, array('titleright' => $labelright));
                 }
                 // For Pieform element textarea or wysiwyg
                 if ($type == 'textarea' || $type == 'wysiwyg') {
                     $cols = $question->getAttribute('cols');
                     if (!isset($cols) || empty($cols)) {
                         $cols = 60;
                     }
                     $rows = $question->getAttribute('rows');
                     if (!isset($rows) || empty($rows)) {
                         $rows = 6;
                     }
                     $question_array = array_merge($question_array, array('cols' => $cols));
                     $question_array = array_merge($question_array, array('rows' => $rows));
                     $question_array = array_merge($question_array, array('resizable' => false));
                 }
                 $steps = $question->getAttribute('scaleSteps');
                 if (isset($steps) && !empty($steps)) {
                     $question_array = array_merge($question_array, array('steps' => $steps));
                 }
                 $reverse = $question->getAttribute('reverseResponse');
                 if (isset($reverse) && !empty($reverse) && return_bool($reverse) == true) {
                     $question_array = array_merge($question_array, array('reverse' => 'true'));
                 }
                 $br2rows = return_bool($question->getAttribute('br2rows'));
                 $separator = '&nbsp;';
                 if ($type == 'radio' || $type == 'checks') {
                     $separator = '<br>';
                 }
                 if (isset($br2rows) && $br2rows) {
                     $question_array = array_merge($question_array, array('br2rows' => true));
                     $question_array = array_merge($question_array, array('separator' => $separator));
                 }
                 // If answers to all questions are required...
                 if ($required_responses) {
                     $question_array = array_merge($question_array, array('rules' => array('required' => true)));
                 }
                 // Create elements array for questions in each fieldset
                 $name = $question->getAttribute('section');
                 if (!isset($name) || empty($name)) {
                     $name = $section->getAttribute('name');
                 }
                 $question_elements_array = array_merge($question_elements_array, array($name . '_' . $question->getAttribute('id') => $question_array));
                 // If allowed, add wysiwyg/textarea for individual question/response comments...
                 $comments = return_bool($question->getAttribute('allowComments'));
                 if (isset($comments) && $comments) {
                     $comments_array = array();
                     $comments_array = array_merge($comments_array, array('type' => 'wysiwyg', 'rows' => 6, 'cols' => 50, 'title' => get_string('addresponsecomments', 'artefact.survey'), 'defaultvalue' => $values['comment_' . $question->getAttribute('id')]));
                     if (isset($br2rows) && $br2rows) {
                         $comments_array = array_merge($comments_array, array('br2rows' => true));
                     }
                     $question_elements_array = array_merge($question_elements_array, array('comment_' . $question->getAttribute('id') => $comments_array));
                 }
             }
             $legend = $section->getAttribute(self::get_default_lang($this->get('title')));
             if ($section->getAttribute('legend') == 'false' || $section->getAttribute('legend') == '0') {
                 //if (return_bool($section->getAttribute('legend')) == false) {
                 $legend = null;
             }
             $pieform_array['elements'] = array_merge($pieform_array['elements'], array($sectiontab => array('type' => 'fieldset', 'legend' => $legend, 'class' => $fieldset != $sectiontab ? 'collapsed' : '', 'elements' => $question_elements_array)));
             $i++;
         }
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('fs' => array('type' => 'hidden', 'value' => $fieldset)));
         $pieform_array['elements'] = array_merge($pieform_array['elements'], array('submit' => array('type' => 'submit', 'value' => get_string('save'))));
     }
     //log_debug($pieform_array);
     return $pieform_array;
 }
Example #17
0
function getClickChoiceQuizArray($ttlQ, $classification, $difficulty)
{
    include 'pdc.php';
    //echo "<meta charset='utf-8'>"; !!! If you try to debug and echo anything out, must echo html charset first!!!!!!!
    try {
        $stmt = $db->prepare("SELECT * \n\t\t\t\t\t\t\t\t\tFROM click_choice \n\t\t\t\t\t\t\t\t\tINNER JOIN cchoice_tags \n\t\t\t\t\t\t\t\t\tON click_choice.id = cchoice_tags.cchoice_ID \n\t\t\t\t\t\t\t\t\tWHERE cchoice_tags.grammar_tag = :classification \n\t\t\t\t\t\t\t\t\tAND cchoice_tags.difficulty_tag=:diff");
        $stmt->execute(array(':classification' => $classification, ':diff' => $difficulty));
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        //Randomly select $ttlQ and return it
        if (count($rows) <= $ttlQ) {
            return $rows;
        } else {
            $shuffledRows = shuffle_assoc($rows);
            $finalRows = array_slice($shuffledRows, 0, $ttlQ);
            return $finalRows;
        }
    } catch (PDOException $ex) {
        //echo "An Error occured!"; //user friendly message
        error_log($ex);
        error_log(mysql_error());
    }
}
Example #18
0
switch ($act) {
    ############################################################################################
    ##                                    Главная страница                                    ##
    ############################################################################################
    case 'index':
        show_title('Облако тегов');
        $config['newtitle'] = 'Блоги - Облако тегов';
        if (@filemtime(DATADIR . "/temp/tagcloud.dat") < time() - 3600) {
            $querytag = DB::run()->query("SELECT `blogs_tags` FROM `blogs`;");
            $tags = $querytag->fetchAll(PDO::FETCH_COLUMN);
            $alltag = implode(',', $tags);
            $dumptags = preg_split('/[\\s]*[,][\\s]*/s', $alltag);
            $arraytags = array_count_values(array_map('utf_lower', $dumptags));
            arsort($arraytags);
            array_splice($arraytags, 50);
            shuffle_assoc($arraytags);
            file_put_contents(DATADIR . "/temp/tagcloud.dat", serialize($arraytags), LOCK_EX);
        }
        $arraytags = unserialize(file_get_contents(DATADIR . "/temp/tagcloud.dat"));
        $max = max($arraytags);
        $min = min($arraytags);
        render('blog/tags', array('tags' => $arraytags, 'max' => $max, 'min' => $min));
        break;
        ############################################################################################
        ##                                    Главная страница                                    ##
        ############################################################################################
    ############################################################################################
    ##                                    Главная страница                                    ##
    ############################################################################################
    case 'search':
        show_title('Поиск по тегам');
Example #19
0
 function generateSoal()
 {
     $id = $_GET['id'];
     $ujian = $this->models->getData('ujian', 0, "id_ujian = {$id}");
     $this->models->delData('generated_soal', "id_ujian = {$ujian['id_ujian']}");
     $paket = $this->models->getData('paket_soal', 1, "id_ujian = {$id} AND status = 1");
     $getSoal = $this->models->getData('master_soal', 1, "id_soal IN ({$paket[0]['id_soal']})");
     $user = $this->models->getidUser();
     $total = count($user);
     $hasil = 0;
     for ($i = 0; $i < $total; $i++) {
         $soal['id_paket'] = $paket[0]['id_paket'];
         $soal['id_kategori'] = $paket[0]['id_kategori'];
         $soal['paket'] = $paket[0]['paket'];
         $soal['durasi_pengerjaan'] = $ujian['lama_ujian'];
         $exp = explode(",", $paket[0]['id_soal']);
         $soal['soal'] = implode(",", shuffle_assoc($exp));
         for ($j = 0; $j < count($exp); $j++) {
             $option = range(1, 4);
             $tmp[$j] = implode(",", fisherYatesShuffle($option, make_seed($j)));
         }
         $soal['opt'] = serialize($tmp);
         $soal['id_peserta'] = $user[$i]['id_peserta'];
         $soal['id_ujian'] = $ujian['id_ujian'];
         // db($soal);
         $success = $this->models->insert_data($soal, 'generated_soal');
         if ($success) {
             $hasil++;
         }
     }
     if ($hasil != 0) {
         return 1;
     } else {
         return 0;
     }
     db('======= Generate Soal Selesai ========');
 }
    }
}
function shuffle_assoc($list)
{
    if (!is_array($list)) {
        return $list;
    }
    $keys = array_keys($list);
    shuffle($keys);
    $random = array();
    foreach ($keys as $key) {
        $random[$key] = $list[$key];
    }
    return $random;
}
$data = shuffle_assoc($data);
foreach ($data as $key => $extension) {
    ?>
                    <div class="theme color<?php 
    echo '' . $color;
    $color++;
    ?>
">
                        <div class="theme-screenshot">
                            <figure>
                                <i class="el <?php 
    echo isset($iconMap[$key]) && !empty($iconMap[$key]) ? 'el-' . $iconMap[$key] : 'el-redux';
    ?>
"></i>
                                <figcaption>
                                    <p><?php 
Example #21
0
<h2>Question <?php 
    echo $num + 1;
    ?>
:</h2>
<p>   <strong><?php 
    echo $questions[$num];
    ?>
</strong>           </p>
<form id="questionBox" method="post" action="test.php">
<ul>
<?php 
    require_once 'functions.php';
    $pattern = ' ';
    $replace = '_';
    $shufled = array();
    $shufled = shuffle_assoc($answers[$num]);
    foreach ($shufled as $answer) {
        $answer2 = str_replace($pattern, $replace, $answer);
        echo "<li><input type=\"radio\" id=\"{$answer2}\" value=\"{$answer2}\" name=\"answers\" />\n";
        echo "<label for=\"{$answer2}\">{$answer}</label></li>\n";
    }
    ?>

</ul>
<p><input type="hidden" name="num" value="<?php 
    echo $num;
    ?>
" />
<input type="hidden" name="submitter" value="TRUE" />
<input type="submit" id="submit" name="submit" value="Submit Answer" /></p>
Example #22
0
/**
 * Find an available agent to assign a ticket to.
 *
 * This is a super basic attribution system. It just finds the agent
 * with the less tickets currently open.
 *
 * @since  3.0.0
 *
 * @param  boolean|integer $ticket_id The ticket that needs an agent
 *
 * @return integer         ID of the best agent for the job
 */
function wpas_find_agent($ticket_id = false)
{
    if (defined('WPAS_DISABLE_AUTO_ASSIGN') && true === WPAS_DISABLE_AUTO_ASSIGN) {
        return apply_filters('wpas_find_available_agent', wpas_get_option('assignee_default'), $ticket_id);
    }
    $users = shuffle_assoc(wpas_get_users(array('cap' => 'edit_ticket')));
    $agent = array();
    foreach ($users as $user) {
        $posts_args = array('post_type' => 'ticket', 'post_status' => 'any', 'posts_per_page' => -1, 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'meta_query' => array(array('key' => '_wpas_status', 'value' => 'open', 'type' => 'CHAR', 'compare' => '='), array('key' => '_wpas_assignee', 'value' => $user->ID, 'type' => 'NUMERIC', 'compare' => '=')));
        $open_tickets = new WP_Query($posts_args);
        $count = count($open_tickets->posts);
        // Total number of open tickets for this agent
        if (empty($agent)) {
            $agent = array('tickets' => $count, 'user_id' => $user->ID);
        } else {
            if ($count < $agent['tickets']) {
                $agent = array('tickets' => $count, 'user_id' => $user->ID);
            }
        }
    }
    return apply_filters('wpas_find_available_agent', $agent['user_id'], $ticket_id);
}
Example #23
0
            <?php 
$random = 50;
$groups = Auth::user()->groups;
$counter = 0;
foreach ($groups as $group) {
    echo '<table class="ui celled table segment">
                            <thead>
                                <tr>
                                    <th>Deutsch</th>
                                    <th>English</th>
                                </tr>   
                            </thead>
                            <tbody>';
    echo "<hr />";
    echo "<h5>" . $group->name . "</h5>";
    $group_words = shuffle_assoc(iterator_to_array($group->words));
    foreach ($group_words as $word) {
        echo "<tr>";
        $rand = rand(1, 100);
        if ($random > $rand) {
            echo "<td>" . $word->german . "</td>";
            echo "<td><input type='text' name='input[]'/></td>";
            echo "<input type='hidden' name='language[]' value='eng' />";
            echo "<input type='hidden' name='statement[]' value='" . $word->german . "' />";
            echo "<input type='hidden' name='statement2[]' value='" . $word->english . "' />";
        } else {
            echo "<td><input type='text' name='input[]'/></td>";
            echo "<input type='hidden' name='language[]' value='ger' />";
            echo "<input type='hidden' name='statement[]' value='" . $word->english . "' />";
            echo "<input type='hidden' name='statement2[]' value='" . $word->german . "' />";
            echo "<td>" . $word->english . "</td>";
Example #24
0
    /**
     * Render Changelog Screen
     *
     * @access public
     * @since  2.0.3
     * @return void
     */
    public function redux_extensions()
    {
        /*
                    repeater =>
                    social profiles =>
                    js button =>
                    multi media =>
                    css layout =>
                    color schemes => adjust-alt
                    custom fonts => fontsize
                    code mirror => view-mode
                    live search => search
                    support faq's => question
                    date time picker =>
                    premium support =>
                    metaboxes =>
                    widget areas =>
                    shortcodes =>
                    icon select => gallery
                    tracking =>
                     * */
        $iconMap = array('repeater' => 'asl', 'social-profiles' => 'group', 'js-button' => 'hand-down', 'multi-media' => 'picture', 'css-layout' => 'fullscreen', 'color-schemes' => 'adjust-alt', 'custom-fonts' => 'fontsize', 'codemirror' => 'view-mode', 'live-search' => 'search', 'support-faqs' => 'question', 'date-time' => 'calendar', 'premium-support' => 'fire', 'metaboxes' => 'magic', 'widget-areas' => 'inbox-box', 'shortcodes' => 'shortcode', 'icon-select' => 'gallery');
        $colors = array('8CC63F', '8CC63F', '0A803B', '25AAE1', '0F75BC', 'F7941E', 'F1592A', 'ED217C', 'BF1E2D', '8569CF', '0D9FD8', '8AD749', 'EECE00', 'F8981F', 'F80E27', 'F640AE');
        shuffle($colors);
        echo '<style type="text/css">';
        ?>

            <?php 
        foreach ($colors as $key => $color) {
            echo '.theme-browser .theme.color' . $key . ' .theme-screenshot{background-color:' . Redux_Helpers::hex2rgba($color, 0.45) . ';}';
            echo '.theme-browser .theme.color' . $key . ':hover .theme-screenshot{background-color:' . Redux_Helpers::hex2rgba($color, 0.75) . ';}';
        }
        echo '</style>';
        $color = 1;
        ?>


            <div class="wrap about-wrap">
                <h1><?php 
        _e('Redux Framework - Extensions', 'redux-framework');
        ?>
</h1>

                <div
                    class="about-text"><?php 
        printf(__('Supercharge your Redux experience. Our extensions provide you with features that will take your products to the next level.', 'redux-framework'), $this->display_version);
        ?>
</div>
                <div
                    class="redux-badge"><i
                        class="el el-redux"></i><span><?php 
        printf(__('Version %s', 'redux-framework'), ReduxFramework::$_version);
        ?>
</span>
                </div>

                <?php 
        $this->tabs();
        ?>

                <p class="about-description"><?php 
        _e("While some are built specificially for developers, extensions such as Custom Fonts are sure to make any user happy.", 'redux-framework');
        ?>
</p>

                <div class="extensions">
                    <div class="feature-section theme-browser rendered" style="clear:both;">
                        <?php 
        $data = get_transient('redux-extensions-fetch');
        if (empty($data)) {
            $data = json_decode(wp_remote_retrieve_body(wp_remote_get('http://reduxframework.com/wp-admin/admin-ajax.php?action=get_redux_extensions')), true);
            if (!empty($data)) {
                set_transient('redux-extensions-fetch', $data, 24 * HOUR_IN_SECONDS);
            }
        }
        function shuffle_assoc($list)
        {
            if (!is_array($list)) {
                return $list;
            }
            $keys = array_keys($list);
            shuffle($keys);
            $random = array();
            foreach ($keys as $key) {
                $random[$key] = $list[$key];
            }
            return $random;
        }
        $data = shuffle_assoc($data);
        foreach ($data as $key => $extension) {
            ?>
                                <div class="theme color<?php 
            echo $color;
            $color++;
            ?>
">
                                    <div class="theme-screenshot">
                                        <figure>
                                            <i class="el <?php 
            echo isset($iconMap[$key]) && !empty($iconMap[$key]) ? 'el-' . $iconMap[$key] : 'el-redux';
            ?>
"></i>
                                            <figcaption>
                                                <p><?php 
            echo $extension['excerpt'];
            ?>
</p>
                                                <a href="<?php 
            echo $extension['url'];
            ?>
" target="_blank">Learn more</a>
                                            </figcaption>
                                        </figure>
                                    </div>
                                    <h3 class="theme-name" id="classic"><?php 
            echo $extension['title'];
            ?>
</h3>

                                    <div class="theme-actions">
                                        <a class="button button-primary button-install-demo"
                                           data-demo-id="<?php 
            echo $key;
            ?>
"
                                           href="<?php 
            echo $extension['url'];
            ?>
" target="_blank">Learn
                                            More</a></div>
                                </div>

                            <?php 
        }
        ?>
                    </div>
                </div>

            </div>
        <?php 
    }
Example #25
0
function calculate_score()
{
    global $score_board;
    global $TOTAL_P_SCORE;
    global $score_P_ratio;
    global $REMAINING_P_SCORE;
    global $LATE_SUBMISSION_PENALTY;
    global $tmDeadline;
    $qCur = new ScorePriorityQueue();
    $qExpire = new ScorePriorityQueue();
    $total_p_score = $TOTAL_P_SCORE;
    $multiplier = -1;
    $qCur->setExtractFlags(ScorePriorityQueue::EXTR_DATA);
    $qExpire->setExtractFlags(ScorePriorityQueue::EXTR_DATA);
    foreach ($score_board as $k => $r) {
        ///// f_score
        if (IsValidScoreboardEntry($k)) {
            //var_dump($score_board[$k]);
            $score_board[$k]["func"] = $score_board[$k]["check"] * pow(0.95, $score_board[$k]["m_error"]);
            if ($score_board[$k]["m_peak"] > 0) {
                $score_board[$k]["func"] *= ($score_board[$k]["m_peak"] - $score_board[$k]["heap_lost"]) / $score_board[$k]["m_peak"];
            }
            if ($r["priority"] > 0) {
                $qCur->insert($k, $r["priority"]);
            }
        } else {
            $score_board[$k]["func"] = 0;
        }
        ////// init p_score
        $score_board[$k]["p_score"] = 0;
        if ($multiplier == -1 || $score_board[$k]["priority"] > $multiplier) {
            $multiplier = $score_board[$k]["priority"];
        }
    }
    if ($multiplier <= 0) {
        $multiplier = 1;
    }
    print $multiplier . "\n";
    while ($qCur->valid() && $total_p_score > 0) {
        $bufExpire = array();
        $qCurSize = $qCur->count();
        while ($qCur->valid()) {
            $idx = $qCur->extract();
            $s = $score_board[$idx]["priority"] / $multiplier;
            // alloted score in the scheduling cycle
            //			print  $score_board[$idx]["priority"]."\n";
            if ($s < 1.0E-5) {
                $s = 1.0E-5;
            }
            if ($s > 100 - $score_board[$idx]["p_score"]) {
                $s = 100 - $score_board[$idx]["p_score"];
            }
            //if ( $s > $total_p_score)
            //	$s = $total_p_score;
            $score_board[$idx]["p_score"] += $s;
            $total_p_score -= $s;
            if ($total_p_score < 0) {
                // Hank 2015.4.6  address uneven score distribution for students with same priority
                $total_p_score = 0;
            }
            if ($score_board[$idx]["p_score"] < 100 && $score_board[$idx]["priority"] > 0) {
                $bufExpire[$idx] = $score_board[$idx]["priority"];
            }
        }
        $bufExpire = shuffle_assoc($bufExpire);
        foreach ($bufExpire as $idx => $priority) {
            $qExpire->insert($idx, $score_board[$idx]["priority"]);
        }
        if ($qCurSize > $qExpire->count() && $qExpire->valid()) {
            // need new  multiplier
            $multiplier = $score_board[$qExpire->top()]["priority"];
            print $multiplier . "\n";
        }
        $qCur = $qExpire;
        $qExpire = new ScorePriorityQueue();
        $qExpire->setExtractFlags(ScorePriorityQueue::EXTR_DATA);
    }
    foreach ($score_board as $k => $r) {
        $score_board[$k]["score"] = min($score_board[$k]["func"] * ((1 - $score_P_ratio) * 100 + $score_board[$k]["p_score"] * $score_P_ratio + $score_board[$k]["diversity"]), 100);
        if (GetSubmissionTime($score_board[$k]['id']) > $tmDeadline) {
            print "user " . $score_board[$k]['id'] . " is late\n";
            $score_board[$k]["score"] -= $LATE_SUBMISSION_PENALTY;
        }
        if ($score_board[$k]["score"] < 0) {
            $score_board[$k]["score"] = 0;
        }
        /// submission time /////
        $score_board[$k]["submission_time"] = date("n/j H:i:s", GetSubmissionTime($score_board[$k]["id"]));
        ////////////////////////
    }
    $REMAINING_P_SCORE = $total_p_score;
    ////////sort by score
    $tmp = array();
    foreach ($score_board as &$ma) {
        $tmp[] = $ma["score"] + $ma["priority"] / 1000;
    }
    array_multisort($tmp, SORT_DESC, $score_board);
}
Example #26
0
	<div id="quote">
		<h2>
			<?php 
// PHP shuffle() breaks hashes
function shuffle_assoc(&$array)
{
    $keys = array_keys($array);
    shuffle($keys);
    foreach ($keys as $key) {
        $new[$key] = $array[$key];
    }
    $array = $new;
    return true;
}
include "quotes.php";
shuffle_assoc($quotes);
$keys = array_keys($quotes);
$values = array_values($quotes);
?>
        <blockquote>
          <?php 
print $keys[0];
?>
  			  <?php 
if (!empty($values[0])) {
    ?>
  			    <cite><a href="<?php 
    print $values[0];
    ?>
">link</a></cite>
  			  <?php 
/**
 * Either prints all of the galleries tgs as a UL list or a cloud
 *
 * @param string $option "cloud" for tag cloud, "list" for simple list
 * @param string $class CSS class
 * @param string $sort "results" for relevance list, "random" for random ordering, otherwise the list is alphabetical
 * @param bool $counter TRUE if you want the tag count within brackets behind the tag
 * @param bool $links set to TRUE to have tag search links included with the tag.
 * @param int $maxfontsize largest font size the cloud should display
 * @param int $maxcount the floor count for setting the cloud font size to $maxfontsize
 * @param int $mincount the minimum count for a tag to appear in the output
 * @param int $limit set to limit the number of tags displayed to the top $numtags
 * @param int $minfontsize minimum font size the cloud should display
 * @param bool $exclude_unassigned True or false if you wish to exclude tags that are not assigne to any item (default: true)
 * @param bool $checkaccess True or false (default: false) if you wish to exclude tags that are assigned to items (or are not assigned at all) the visitor is not allowed to see
 * Beware that this may cause overhead on large sites. Usage of the static_html_cache is strongely recommended then.
 * @since 1.1
 */
function printAllTagsAs($option, $class = '', $sort = NULL, $counter = FALSE, $links = TRUE, $maxfontsize = 2, $maxcount = 50, $mincount = 1, $limit = NULL, $minfontsize = 0.8, $exclude_unassigned = true, $checkaccess = false)
{
    global $_zp_current_search;
    $option = strtolower($option);
    if ($class != "") {
        $class = ' class="' . $class . '"';
    }
    $tagcount = getAllTagsCount($exclude_unassigned, $checkaccess);
    if (!is_array($tagcount)) {
        return false;
    }
    switch ($sort) {
        case 'results':
            arsort($tagcount);
            if (!is_null($limit)) {
                $tagcount = array_slice($tagcount, 0, $limit);
            }
            break;
        case 'random':
            if (!is_null($limit)) {
                $tagcount = array_slice($tagcount, 0, $limit);
            }
            shuffle_assoc($tagcount);
            break;
        default:
            break;
    }
    ?>
	<ul<?php 
    echo $class;
    ?>
>
		<?php 
    if (count($tagcount) > 0) {
        foreach ($tagcount as $key => $val) {
            if (!$counter) {
                $counter = "";
            } else {
                $counter = " (" . $val . ") ";
            }
            if ($option == "cloud") {
                // calculate font sizes, formula from wikipedia
                if ($val <= $mincount) {
                    $size = $minfontsize;
                } else {
                    $size = min(max(round($maxfontsize * ($val - $mincount) / ($maxcount - $mincount), 2), $minfontsize), $maxfontsize);
                }
                $size = str_replace(',', '.', $size);
                $size = ' style="font-size:' . $size . 'em;"';
            } else {
                $size = '';
            }
            if ($val >= $mincount) {
                if ($links) {
                    if (is_object($_zp_current_search)) {
                        $albumlist = $_zp_current_search->getAlbumList();
                    } else {
                        $albumlist = NULL;
                    }
                    $link = getSearchURL(search_quote($key), '', 'tags', 0, array('albums' => $albumlist));
                    ?>
						<li>
							<a href="<?php 
                    echo html_encode($link);
                    ?>
"<?php 
                    echo $size;
                    ?>
><?php 
                    echo $key . $counter;
                    ?>
</a>
						</li>
						<?php 
                } else {
                    ?>
						<li<?php 
                    echo $size;
                    ?>
><?php 
                    echo $key . $counter;
                    ?>
</li>
						<?php 
                }
            }
        }
        // while end
    } else {
        ?>
			<li><?php 
        echo gettext('No popular tags');
        ?>
</li>
			<?php 
    }
    ?>
	</ul>
	<?php 
}
/**
 * Either prints all of the galleries tgs as a UL list or a cloud
 *
 * @param string $option "cloud" for tag cloud, "list" for simple list
 * @param string $class CSS class
 * @param string $sort "results" for relevance list, "random" for random ordering, otherwise the list is alphabetical
 * @param bool $counter TRUE if you want the tag count within brackets behind the tag
 * @param bool $links set to TRUE to have tag search links included with the tag.
 * @param int $maxfontsize largest font size the cloud should display
 * @param int $maxcount the floor count for setting the cloud font size to $maxfontsize
 * @param int $mincount the minimum count for a tag to appear in the output
 * @param int $limit set to limit the number of tags displayed to the top $numtags
 * @param int $minfontsize minimum font size the cloud should display
 * @since 1.1
 */
function printAllTagsAs($option, $class = '', $sort = NULL, $counter = FALSE, $links = TRUE, $maxfontsize = 2, $maxcount = 50, $mincount = 10, $limit = NULL, $minfontsize = 0.8)
{
    global $_zp_current_search;
    $option = strtolower($option);
    if ($class != "") {
        $class = ' class="' . $class . '"';
    }
    $tagcount = getAllTagsUnique(NULL, $mincount, true);
    if (!is_array($tagcount)) {
        return false;
    }
    arsort($tagcount);
    if (!is_null($limit)) {
        $tagcount = array_slice($tagcount, 0, $limit);
    }
    $keys = array_keys($tagcount);
    switch ($sort) {
        default:
            natcasesort($keys);
            break;
        case 'results':
            //already in tag count order
            break;
        case 'random':
            shuffle_assoc($keys);
            break;
    }
    ?>
	<ul<?php 
    echo $class;
    ?>
>
		<?php 
    if (count($tagcount) > 0) {
        foreach ($keys as $key) {
            $val = $tagcount[$key];
            if (!$counter) {
                $counter = "";
            } else {
                $counter = " (" . $val . ") ";
            }
            if ($option == "cloud") {
                // calculate font sizes, formula from wikipedia
                if ($val <= $mincount) {
                    $size = $minfontsize;
                } else {
                    $size = min(max(round($maxfontsize * ($val - $mincount) / ($maxcount - $mincount), 2), $minfontsize), $maxfontsize);
                }
                $size = str_replace(',', '.', $size);
                $size = ' style="font-size:' . $size . 'em;"';
            } else {
                $size = '';
            }
            if ($links) {
                if (is_object($_zp_current_search)) {
                    $albumlist = $_zp_current_search->getAlbumList();
                } else {
                    $albumlist = NULL;
                }
                $link = getSearchURL(search_quote($key), '', 'tags', 0, array('albums' => $albumlist));
                ?>
					<li>
						<a href="<?php 
                echo html_encode($link);
                ?>
" rel="nofollow"<?php 
                echo $size;
                ?>
><?php 
                echo str_replace(' ', '&nbsp;', html_encode($key)) . $counter;
                ?>
</a>
					</li>
					<?php 
            } else {
                ?>
					<li<?php 
                echo $size;
                ?>
><?php 
                echo str_replace(' ', '&nbsp;', html_encode($key)) . $counter;
                ?>
</li>
					<?php 
            }
        }
    } else {
        ?>
			<li><?php 
        echo gettext('No popular tags');
        ?>
</li>
			<?php 
    }
    ?>
	</ul>
	<?php 
}
/**
 * Find an available agent to assign a ticket to.
 *
 * This is a super basic attribution system. It just finds the agent
 * with the less tickets currently open.
 *
 * @since  3.0.0
 *
 * @param  boolean|integer $ticket_id The ticket that needs an agent
 *
 * @return integer         ID of the best agent for the job
 */
function wpas_find_agent($ticket_id = false)
{
    if (defined('WPAS_DISABLE_AUTO_ASSIGN') && true === WPAS_DISABLE_AUTO_ASSIGN) {
        return apply_filters('wpas_find_available_agent', wpas_get_option('assignee_default'), $ticket_id);
    }
    $users = shuffle_assoc(wpas_get_users(apply_filters('wpas_find_agent_get_users_args', array('cap' => 'edit_ticket'))));
    $agent = array();
    foreach ($users->members as $user) {
        $wpas_agent = new WPAS_Member_Agent($user);
        /**
         * Make sure the user really is an agent and that he can currently be assigned
         */
        if (true !== $wpas_agent->is_agent() || false === $wpas_agent->can_be_assigned()) {
            continue;
        }
        $count = $wpas_agent->open_tickets();
        // Total number of open tickets for this agent
        if (empty($agent)) {
            $agent = array('tickets' => $count, 'user_id' => $user->ID);
        } else {
            if ($count < $agent['tickets']) {
                $agent = array('tickets' => $count, 'user_id' => $user->ID);
            }
        }
    }
    if (is_array($agent) && isset($agent['user_id'])) {
        $agent_id = $agent['user_id'];
    } else {
        $default_id = wpas_get_option('assignee_default', 1);
        if (empty($default_id)) {
            $default_id = 1;
        }
        $agent_id = $default_id;
    }
    return apply_filters('wpas_find_available_agent', (int) $agent_id, $ticket_id);
}
Example #30
0
 /**
  * Show the cloud sideblock
  * @param type TAGS or CATEGORY
  */
 function showBlockCloud($type)
 {
     global $imSettings;
     $max = 0;
     if ($type == "tags") {
         $tags = array();
         foreach ($imSettings['blog']['posts'] as $id => $post) {
             foreach ($post['tag'] as $tag) {
                 if ($tags[$tag] == null) {
                     $tags[$tag] = 1;
                 } else {
                     $tags[$tag] = $tags[$tag] + 1;
                 }
                 if ($tags[$tag] > $max) {
                     $max = $tags[$tag];
                 }
             }
         }
         $tags = shuffle_assoc($tags);
         $min_em = 0.7;
         $max_em = 1.3;
         foreach ($tags as $name => $number) {
             $size = number_format($number / $max * ($max_em - $min_em) + $min_em, 2, '.', '');
             echo "<span class=\"imBlogCloudItem\" style=\"font-size: " . $size . "em;\"><a href=\"?tag=" . $name . "\">" . str_replace("_", " ", $name) . "</a></span>\n";
         }
     } else {
         if ($type == "categories") {
             $categories = array();
             foreach ($imSettings['blog']['posts'] as $id => $post) {
                 if ($categories[$post['category']] == null) {
                     $categories[$post['category']] = 1;
                 } else {
                     $categories[$post['category']] = $categories[$post['category']] + 1;
                 }
                 if ($categories[$post['category']] > $max) {
                     $max = $categories[$post['category']];
                 }
             }
             $categories[$category] = shuffle_assoc($categories[$category]);
             $min_em = 0.7;
             $max_em = 1.3;
             foreach ($categories as $name => $number) {
                 $size = number_format($number / $max * ($max_em - $min_em) + $min_em, 2, '.', '');
                 echo "<span class=\"imBlogCloudItem\" style=\"font-size: " . $size . "em;\"><a href=\"?category=" . str_replace(" ", "_", $name) . "\">" . $name . "</a></span>\n";
             }
         }
     }
 }