Example #1
0
 private function getPairingOrdering()
 {
     // Perf improvement. 10mins => 25s by ordering in sensible order to start.
     masort($this->players, 'points_d', false);
     $bestPossible = $this->bestPossible();
     $size = count($this->players) - 1;
     $perm = range(0, $size);
     $j = 0;
     $best = null;
     $bestScore = PHP_INT_MAX;
     do {
         $thisPerm = [];
         foreach ($perm as $i) {
             $thisPerm[] = $this->players[$i];
         }
         $thisScore = $this->scorePairings($thisPerm, $bestScore);
         // Optimization. Short circuit if we've found a theoretically optimal set.
         if ($thisScore <= $bestPossible) {
             return $thisPerm;
         }
         if ($thisScore < $bestScore) {
             $best = $thisPerm;
             $bestScore = $thisScore;
         }
     } while ($perm = $this->nextPermutation($perm, $size) and ++$j);
     return $best;
 }
 /**
  * Get a list of available commands.
  */
 public function getCommandList()
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     $config = $this->getConfigArray(false);
     masort($config['command'], 'summary');
     if (isset($config['command']) && is_array($config['command'])) {
         return $config['command'];
     } else {
         return array();
     }
 }
Example #3
0
 public function getAttrDisplayOrder()
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     $result = array();
     if (count($this->attributes)) {
         masort($this->attributes, 'order');
         foreach ($this->attributes as $attribute) {
             array_push($result, $attribute->getName());
         }
     } else {
         $display = preg_replace('/,\\s+/', ',', get_request('display_attrs', 'REQUEST', false, ''));
         if (trim($display)) {
             $result = explode(',', $display);
         }
     }
     # If our display order is empty, then dynamically build it
     if (!count($result)) {
         foreach ($this->results as $details) {
             foreach ($details as $attrs) {
                 $result = array_merge($result, array_keys(array_change_key_case($attrs)));
             }
         }
         $result = array_unique($result);
         sort($result);
     }
     # Put the DN first
     array_unshift($result, 'dn');
     $result = array_unique($result);
     return implode(',', $result);
 }
 /**
  * Gets an array of AttributeType objects that entries of this ObjectClass may define.
  * This differs from getMayAttrNames in that it returns an array of AttributeType objects
  *
  * @param array $parents An array of ObjectClass objects to use when traversing
  *             the inheritance tree. This presents some what of a bootstrapping problem
  *             as we must fetch all objectClasses to determine through inheritance which
  *             attributes this objectClass provides.
  * @return array The array of allowed AttributeType objects.
  *
  * @see getMustAttrNames
  * @see getMustAttrs
  * @see getMayAttrNames
  * @see AttributeType
  */
 public function getMayAttrs($parents = false)
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     if (!$parents) {
         return $this->may_attrs;
     }
     $server = $_SESSION[APPCONFIG]->getServer($this->server_id);
     $attrs = $this->may_attrs;
     foreach ($this->getParents() as $sup_class) {
         $sc = $server->getSchemaObjectClass($sup_class);
         $attrs = array_merge($attrs, $sc->getMayAttrs());
     }
     masort($attrs, 'name,source');
     # Remove any duplicates
     foreach ($attrs as $index => $attr) {
         if (isset($allattr[$attr->name])) {
             unset($attrs[$index]);
         } else {
             $allattr[$attr->name] = 1;
         }
     }
     return $attrs;
 }
Example #5
0
 function get_class_reportFN($id_course, $order = "", $index_att = "", $type = 'HTML')
 {
     $dh = $GLOBALS['dh'];
     $http_root_dir = $GLOBALS['http_root_dir'];
     $debug = isset($GLOBALS['debug']) ? $GLOBALS['debug'] : null;
     $npar = isset($GLOBALS['npar']) ? $GLOBALS['npar'] : null;
     $hpar = isset($GLOBALS['hpar']) ? $GLOBALS['hpar'] : null;
     $mpar = isset($GLOBALS['mpar']) ? $GLOBALS['mpar'] : null;
     $epar = isset($GLOBALS['epar']) ? $GLOBALS['epar'] : null;
     $bpar = isset($GLOBALS['mpar']) ? $GLOBALS['mpar'] : null;
     $cpar = isset($GLOBALS['epar']) ? $GLOBALS['epar'] : null;
     // default parameters for activity index are in configuration file
     if (empty($npar)) {
         $npar = NOTE_PAR;
     }
     // notes
     if (!isset($hpar)) {
         $hpar = HIST_PAR;
     }
     // history
     if (!isset($mpar)) {
         $mpar = MSG_PAR;
     }
     //messages
     if (!isset($epar)) {
         $epar = EXE_PAR;
     }
     // exercises
     if (!isset($bpar)) {
         $bpar = defined('BKM_PAR') ? BKM_PAR : null;
     }
     //bookmarks
     if (!isset($cpar)) {
         $cpar = defined('CHA_PAR') ? CHA_PAR : null;
     }
     // chat
     $student_list_ar = $this->student_list;
     $id_instance = $this->id;
     if ($student_list_ar != 0) {
         $info_course = $dh->get_course($id_course);
         // Get title course
         if (AMA_DataHandler::isError($info_course)) {
             $msg = $info_course->getMessage();
             return $msg;
         }
         $course_title = $info_course['titolo'];
         $instance_course_ha = $dh->course_instance_get($id_instance);
         // Get the instance courses data
         if (AMA_DataHandler::isError($instance_course_ha)) {
             $msg = $instance_course_ha->getMessage();
             return $msg;
         }
         $start_date = AMA_DataHandler::ts_to_date($instance_course_ha['data_inizio'], ADA_DATE_FORMAT);
         $num_student = -1;
         $tot_history_count = 0;
         $tot_exercises_score = 0;
         $tot_exercises_number = 0;
         $tot_added_notes = 0;
         $tot_read_notes = 0;
         $tot_message_count = 0;
         $tot_message_count_in = 0;
         $tot_message_count_out = 0;
         $tot_bookmarks_count = 0;
         $tot_chatlines_count_out = 0;
         $tot_index = 0;
         $tot_level = 0;
         /**
          * @author giorgio 27/ott/2014
          * 
          * change to:
          * $report_generation_TS = time();
          * 
          * to have full date & time generation of report
          * but be warned that table log_classi may grow A LOT!
          */
         $report_generation_TS = dt2tsFN(today_dateFN());
         if (MODULES_TEST) {
             $tot_exercises_score_test = 0;
             $tot_exercises_number_test = 0;
             $tot_exercises_score_survey = 0;
             $tot_exercises_number_survey = 0;
             $test_db = AMATestDataHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester']));
             $test_score = $test_db->getStudentsScores($id_course, $id_instance);
         }
         foreach ($student_list_ar as $one_student) {
             $num_student++;
             //starts with 0
             $id_student = $one_student['id_utente_studente'];
             $student_level = $one_student['livello'];
             $status_student = $one_student['status'];
             $dati['id'] = $id_student;
             $dati['level'] = $student_level;
             $ymdhms = today_dateFN();
             $utime = dt2tsFN($ymdhms);
             $dati['date'] = $report_generation_TS;
             if (!empty($id_student) and ($status_student == ADA_STATUS_SUBSCRIBED or $status_student == ADA_SERVICE_SUBSCRIPTION_STATUS_COMPLETED)) {
                 $studentObj = MultiPort::findUser($id_student);
                 //new Student($id_student,$id_instance);
                 if ($studentObj->full != 0) {
                     //==0) {
                     $err_msg = $studentObj->error_msg;
                 } else {
                     if ($studentObj instanceof ADAPractitioner) {
                         /**
                          * @author giorgio 14/apr/2015
                          * 
                          * If student is actually a tutor, build a new student
                          * object for history and evaluation purposes
                          */
                         $studentObj = $studentObj->toStudent();
                     }
                     $student_name = $studentObj->getFullname();
                     //$studentObj->nome." ".$studentObj->cognome;
                     // vito
                     $studentObj->set_course_instance_for_history($id_instance);
                     //$studentObj->history->setCourseInstance($id_instance);
                     $studentObj->history->setCourse($id_course);
                     $studentObj->get_exercise_dataFN($id_instance, $id_student);
                     $st_exercise_dataAr = $studentObj->user_ex_historyAr;
                     $st_score = 0;
                     $st_exer_number = 0;
                     if (is_array($st_exercise_dataAr)) {
                         foreach ($st_exercise_dataAr as $exercise) {
                             $st_score += $exercise[7];
                             $st_exer_number++;
                         }
                     }
                     $dati['exercises'] = $st_exer_number;
                     $dati['score'] = $st_score;
                     if (MODULES_TEST) {
                         $st_score_test = isset($test_score[$id_student]['score_test']) ? $test_score[$id_student]['score_test'] : 0;
                         $st_exer_number_test = isset($test_score[$id_student]['max_score_test']) ? $test_score[$id_student]['max_score_test'] : 0;
                         $dati['exercises_test'] = $st_exer_number_test;
                         $dati['score_test'] = $st_score_test;
                         $st_score_survey = isset($test_score[$id_student]['score_survey']) ? $test_score[$id_student]['score_survey'] : 0;
                         $st_exer_number_survey = isset($test_score[$id_student]['max_score_survey']) ? $test_score[$id_student]['max_score_survey'] : 0;
                         $dati['exercises_survey'] = $st_exer_number_survey;
                         $dati['score_survey'] = $st_score_survey;
                     }
                     $sub_courses = $dh->get_subscription($id_student, $id_instance);
                     if ($sub_courses['tipo'] == ADA_STATUS_SUBSCRIBED) {
                         $out_fields_ar = array('nome', 'titolo', 'id_istanza', 'data_creazione');
                         $clause = "tipo = '" . ADA_NOTE_TYPE . "' AND id_utente = '{$id_student}'";
                         $nodes = $dh->find_course_nodes_list($out_fields_ar, $clause, $id_course);
                         $added_nodes_count = count($nodes);
                         $added_nodes_count_norm = str_pad($added_nodes_count, 5, "0", STR_PAD_LEFT);
                         $added_notes = "<!-- {$added_nodes_count_norm} --><a href={$http_root_dir}/tutor/tutor.php?op=student_notes&id_instance={$id_instance}&id_student={$id_student}>" . $added_nodes_count . "</a>";
                         //$added_notes = $added_nodes_count;
                     } else {
                         $added_notes = "<!-- 0 -->-";
                     }
                     $read_notes_count = $studentObj->total_visited_notesFN($id_student, $id_course);
                     if ($read_notes_count > 0) {
                         $read_nodes_count_norm = str_pad($read_notes_count, 5, "0", STR_PAD_LEFT);
                         $read_notes = "<!-- {$read_nodes_count_norm} -->{$read_notes_count}";
                     } else {
                         $read_notes = "<!-- 0 -->-";
                     }
                     $st_history_count = "0";
                     $debug = 0;
                     $st_history_count = $studentObj->total_visited_nodesFN($id_student, ADA_LEAF_TYPE);
                     // vito, 11 mar 2009. Ottiene solo il numero di visite a nodi di tipo foglia.
                     // vogliamo anche il numero di visite a nodi di tipo gruppo.
                     $st_history_count += $studentObj->total_visited_nodesFN($id_student, ADA_GROUP_TYPE);
                     $dati['visits'] = $st_history_count;
                     $st_name = "<!-- {$student_name} --><a href=" . $http_root_dir . "/tutor/tutor.php?op=zoom_student&id_student=" . $id_student;
                     $st_name .= "&id_course=" . $id_course . "&id_instance=" . $id_instance . ">";
                     $st_name .= $student_name . "</a>";
                     $st_history_count_norm = str_pad($st_history_count, 5, "0", STR_PAD_LEFT);
                     $st_history = "<!-- {$st_history_count_norm} --><a href=" . $http_root_dir . "/tutor/tutor_history.php?id_student=" . $id_student;
                     $st_history .= "&id_course=" . $id_course . "&id_course_instance=" . $id_instance . ">";
                     $st_history .= $st_history_count . "</a>";
                     $st_history_last_access = $studentObj->get_last_accessFN($id_instance, "T");
                     //$dati['date'] = $st_history_last_access;
                     $st_score_norm = str_pad($st_score, 5, "0", STR_PAD_LEFT);
                     $st_exercises = "<!-- {$st_score_norm} --><a href=" . $http_root_dir . "/tutor/tutor_exercise.php?id_student=" . $id_student;
                     $st_exercises .= "&id_course_instance=" . $id_instance . " class='dontwrap'>";
                     $st_exercises .= $st_score . " " . translateFN("su") . " " . $st_exer_number * ADA_MAX_SCORE . "</a>";
                     if (MODULES_TEST) {
                         $st_score_norm_test = str_pad($st_score_test, 5, "0", STR_PAD_LEFT);
                         $st_exercises_test = '<!-- ' . $st_score_norm_test . ' --><a href="' . MODULES_TEST_HTTP . '/tutor.php?op=test&id_course_instance=' . $id_instance . '&id_course=' . $id_course . '&id_student=' . $id_student . '" class="dontwrap">' . $st_score_test . ' ' . translateFN('su') . ' ' . $st_exer_number_test . '</a>';
                         $st_score_norm_survey = str_pad($st_score_survey, 5, "0", STR_PAD_LEFT);
                         $st_exercises_survey = '<!-- ' . $st_score_norm_survey . ' --><a href="' . MODULES_TEST_HTTP . '/tutor.php?op=survey&id_course_instance=' . $id_instance . '&id_course=' . $id_course . '&id_student=' . $id_student . '" class="dontwrap">' . $st_score_survey . ' ' . translateFN('su') . ' ' . $st_exer_number_survey . '</a>';
                     }
                     // user data
                     $dati_stude[$num_student]['id'] = $id_student;
                     $dati_stude[$num_student]['student'] = $st_name;
                     // history
                     $dati_stude[$num_student]['history'] = $st_history;
                     $tot_history_count += $st_history_count;
                     if ($st_history_last_access != "-") {
                         $dati_stude[$num_student]['last_access'] = "<a href=\"{$http_root_dir}/tutor/tutor_history_details.php?period=1&id_student={$id_student}&id_course_instance={$id_instance}&id_course={$id_course}\">" . $st_history_last_access . "</a>";
                         $dati['last_access'] = $studentObj->get_last_accessFN($id_instance, 'UT');
                     } else {
                         $dati_stude[$num_student]['last_access'] = $st_history_last_access;
                         $dati['last_access'] = null;
                     }
                     // exercises
                     $tot_exercises_score += $st_score;
                     $tot_exercises_number += $st_exer_number;
                     $dati_stude[$num_student]['exercises'] = $st_exercises;
                     $dati['exercises'] = $st_exer_number;
                     if (MODULES_TEST) {
                         $tot_exercises_score_test += $st_score_test;
                         $tot_exercises_number_test += $st_exer_number_test;
                         $dati_stude[$num_student]['exercises_test'] = $st_exercises_test;
                         $dati['exercises_test'] = $st_exer_number_test;
                         $tot_exercises_score_survey += $st_score_survey;
                         $tot_exercises_number_survey += $st_exer_number_survey;
                         $dati_stude[$num_student]['exercises_survey'] = $st_exercises_survey;
                         $dati['exercises_survey'] = $st_exer_number_survey;
                     }
                     // forum notes written
                     $dati_stude[$num_student]['added_notes'] = $added_notes;
                     $tot_added_notes += $added_nodes_count;
                     $dati['added_notes'] = $added_nodes_count;
                     // forum notes read
                     $dati_stude[$num_student]['read_notes'] = $read_notes;
                     $tot_read_notes += $read_notes_count;
                     $dati['read_notes'] = $read_notes_count;
                     // messages
                     //$mh = new MessageHandler("%d/%m/%Y - %H:%M:%S");
                     $mh = MessageHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester']));
                     $sort_field = "data_ora desc";
                     // messages received
                     $msgs_ha = $mh->get_messages($id_student, ADA_MSG_SIMPLE, array("id_mittente", "data_ora"), $sort_field);
                     if (AMA_DataHandler::isError($msgs_ha)) {
                         $err_code = $msgs_ha->code;
                         $dati_stude[$num_student]['message_count_in'] = "-";
                     } else {
                         $user_message_count = count($msgs_ha);
                         $dati_stude[$num_student]['message_count_in'] = $user_message_count;
                         $tot_message_count += $user_message_count;
                     }
                     $tot_message_count_in += $user_message_count;
                     $dati['msg_in'] = $user_message_count;
                     // messages sent
                     $msgs_ha = $mh->get_sent_messages($id_student, ADA_MSG_SIMPLE, array("id_mittente", "data_ora"), $sort_field);
                     if (AMA_DataHandler::isError($msgs_ha)) {
                         $err_code = $msgs_ha->code;
                         $dati_stude[$num_student]['message_count_out'] = "-";
                     } else {
                         $user_message_count = count($msgs_ha);
                         $dati_stude[$num_student]['message_count_out'] = $user_message_count;
                         $tot_message_count += $user_message_count;
                     }
                     $tot_message_count_out += $user_message_count;
                     $dati['msg_out'] = $user_message_count;
                     //chat..
                     $msgs_ha = $mh->get_sent_messages($id_student, ADA_MSG_CHAT, array("id_mittente", "data_ora"), $sort_field);
                     if (AMA_DataHandler::isError($msgs_ha)) {
                         $err_code = $msgs_ha->code;
                         $dati_stude[$num_student]['chat'] = "-";
                     } else {
                         $chatlines_count_out = count($msgs_ha);
                         $dati_stude[$num_student]['chat'] = $chatlines_count_out;
                         $tot_chatlines_count_out += $chatlines_count_out;
                     }
                     $tot_chatlines_count_out += $chatlines_count_out;
                     $dati['chat'] = $chatlines_count_out;
                     //bookmarks..
                     include_once 'bookmark_class.inc.php';
                     $bookmarks_count = count(Bookmark::get_bookmarks($id_student));
                     $dati_stude[$num_student]['bookmarks'] = $bookmarks_count;
                     $tot_bookmarks_count += $bookmarks_count;
                     $dati['bookmarks'] = $bookmarks_count;
                     // activity index
                     if (empty($index_att)) {
                         // parametro passato alla funzione
                         if (empty($GLOBALS['index_activity_expression'])) {
                             //
                             if (!isset($bcount)) {
                                 $bcount = 1;
                             }
                             $index = $added_nodes_count * $npar + $st_history_count * $hpar + $user_message_count * $mpar + $st_exer_number * $epar + $bookmarks_count * $bcount + $chatlines_count_out * $cpar;
                         } else {
                             $index = eval($GLOBALS['index_activity_expression']);
                         }
                     } else {
                         $index = eval($index_att);
                     }
                     $dati_stude[$num_student]['index'] = $index;
                     //echo $index;
                     $tot_index += $index;
                     $dati['index'] = $index;
                     // level
                     $tot_level += $student_level;
                     $dati_stude[$num_student]['level'] = '<span id="studentLevel_' . $id_student . '">' . $student_level . '</span>';
                     $forceUpdate = false;
                     $linksHtml = $this->generateLevelButtons($id_student, $forceUpdate);
                     $dati_stude[$num_student]['level_plus'] = !is_null($linksHtml) ? $linksHtml : '-';
                     // inserting a row in table log_classi
                     $this->log_class_data($id_course, $id_instance, $dati);
                 }
             }
         }
         // average data
         $tot_students = $num_student + 1;
         $av_history = $tot_history_count / $tot_students;
         $av_exercises = $tot_exercises_score / $tot_students . " " . translateFN("su") . " " . floor($tot_exercises_number * ADA_MAX_SCORE / $tot_students);
         if (MODULES_TEST) {
             $av_exercises_test = round($tot_exercises_score_test / $tot_students, 2) . ' ' . translateFN('su') . ' ' . floor($tot_exercises_number_test / $tot_students);
             $av_exercises_survey = round($tot_exercises_score_survey / $tot_students, 2) . ' ' . translateFN('su') . ' ' . floor($tot_exercises_number_survey / $tot_students);
         }
         $av_added_notes = $tot_added_notes / $tot_students;
         $av_read_notes = $tot_read_notes / $tot_students;
         $av_message_count_in = $tot_message_count_in / $tot_students;
         $av_message_count_out = $tot_message_count_out / $tot_students;
         $av_chat_count_out = $tot_chatlines_count_out / $tot_students;
         $av_bookmarks_count = $tot_bookmarks_count / $tot_students;
         $av_index = $tot_index / $tot_students;
         $av_level = $tot_level / $tot_students;
         $av_student = $tot_students;
         $dati_stude[$av_student]['id'] = "-";
         $dati_stude[$av_student]['student'] = translateFN("Media");
         $dati_stude[$av_student]['history'] = round($av_history, 2);
         $dati_stude[$av_student]['last_access'] = "-";
         $dati_stude[$av_student]['exercises'] = '<span class="dontwrap">' . $av_exercises . '</span>';
         if (MODULES_TEST) {
             $dati_stude[$av_student]['exercises_test'] = '<span class="dontwrap">' . $av_exercises_test . '</span>';
             $dati_stude[$av_student]['exercises_survey'] = '<span class="dontwrap">' . $av_exercises_survey . '</span>';
         }
         $dati_stude[$av_student]['added_notes'] = round($av_added_notes, 2);
         $dati_stude[$av_student]['read_notes'] = round($av_read_notes, 2);
         $dati_stude[$av_student]['message_count_in'] = round($av_message_count_in, 2);
         $dati_stude[$av_student]['message_count_out'] = round($av_message_count_out, 2);
         $dati_stude[$av_student]['chat'] = round($av_chat_count_out, 2);
         $dati_stude[$av_student]['bookmarks'] = round($av_bookmarks_count, 2);
         $dati_stude[$av_student]['index'] = round($av_index, 2);
         $dati_stude[$av_student]['level'] = '<span id="averageLevel">' . round($av_level, 2) . '</span>';
         $dati_stude[$av_student]['level_plus'] = "-";
         // @author giorgio 16/mag/2013
         // was $dati_stude[$av_student]['level_minus'] = "-";
         // $dati_stude[$av_student]['level_less'] = "-";
         if (!empty($order)) {
             //var_dump($dati_stude);
             $dati_stude = masort($dati_stude, $order, 1, SORT_NUMERIC);
         }
         // TABLE LABELS
         $table_labels[0] = $this->generate_class_report_header();
         /**
          * @author giorgio 16/mag/2013
          * 
          * unset the unwanted columns data and labels. unwanted cols are defined in config/config_class_report.inc.php
          */
         $arrayToUse = 'report' . $type . 'ColArray';
         $this->clean_class_reportFN($arrayToUse, $table_labels, $dati_stude);
         return array('report_generation_date' => $report_generation_TS) + array_merge($table_labels, $dati_stude);
     } else {
         return null;
     }
 }
 function Templates($server_id)
 {
     if (DEBUG_ENABLED) {
         debug_log('%s::__construct(): Entered with ()', 5, get_class($this));
     }
     if ($this->_template = get_cached_item($server_id, 'template', 'all')) {
         if (DEBUG_ENABLED) {
             debug_log('%s::init(): Using CACHED [%s]', 5, get_class($this), 'templates');
         }
     } else {
         $dir = opendir(TMPLDIR);
         $this->template_num = 0;
         while (($file = readdir($dir)) !== false) {
             if (!preg_match('/.xml$/', $file)) {
                 continue;
             }
             $objXML = new xml2array();
             $xmldata = $objXML->parse(TMPLDIR . $file);
             $template_name = preg_replace('/.xml$/', '', $file);
             $this->storeTemplate($template_name, $xmldata);
         }
         masort($this->_template, 'title');
         set_cached_item($server_id, 'template', 'all', $this->_template);
     }
 }
Example #7
0
 /**
  * Get a list of all the configured servers.
  *
  * @param boolean Only show visible servers.
  * @return array list of all configured servers.
  */
 public function getServerList($isVisible = true)
 {
     if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     static $CACHE;
     if (isset($CACHE[$isVisible])) {
         return $CACHE[$isVisible];
     }
     $CACHE[$isVisible] = array();
     # Debugging incase objects is not set.
     if (!$this->objects) {
         print "<PRE>";
         debug_print_backtrace();
         die;
     }
     foreach ($this->objects as $id => $server) {
         if (!$isVisible || $isVisible && $server->getValue('server', 'visible')) {
             $CACHE[$isVisible][$id] = $server;
         }
     }
     masort($CACHE[$isVisible], 'name');
     return $CACHE[$isVisible];
 }
Example #8
0
/**
 * Query LDAP and return a hash.
 *
 * @param string The base DN to use.
 * @param string LDAP Query filter.
 * @param string LDAP attribute to use as key.
 * @param array Attributes to use as values.
 * @param boolean Specify false to not sort results by DN
 *                or true to have the returned array sorted by DN (uses ksort)
 *                or an array of attribute names to sort by attribute values
 * @return array Array of values keyed by $key.
 */
function return_ldap_hash($base, $filter, $key, $attrs, $sort = true)
{
    if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
        debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    }
    $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id', 'REQUEST'));
    $key = strtolower($key);
    $query = array();
    $query['base'] = $base;
    $query['filter'] = $filter;
    $query['attrs'] = $attrs;
    $search = $server->query($query, null);
    $results = array();
    foreach ($search as $dn => $values) {
        if (isset($values[$key])) {
            if (is_array($values[$key])) {
                foreach ($values[$key] as $i => $k) {
                    foreach ($attrs as $attr) {
                        $lattr = strtolower($attr);
                        if (isset($values[$lattr])) {
                            $v = '';
                            if (is_array($values[$lattr]) && isset($values[$lattr][$i])) {
                                $v = $values[$lattr][$i];
                            }
                            if (is_string($v) && strlen($v) > 0) {
                                $results[$k][$attr] = $v;
                            }
                        }
                    }
                }
            } else {
                foreach ($attrs as $attr) {
                    $lattr = strtolower($attr);
                    if (isset($values[$lattr])) {
                        $results[$values[$key]][$attr] = $values[$lattr];
                    }
                }
            }
        }
    }
    if ($sort) {
        masort($results, is_array($sort) ? implode(',', $sort) : 'dn');
    }
    return $results;
}
Example #9
0
 function __construct($server_id)
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     $this->server_id = $server_id;
     $server = $_SESSION[APPCONFIG]->getServer($this->server_id);
     $custom_prefix = $server->getValue('custom', 'pages_prefix');
     $class = $this->getClassVars();
     $changed = false;
     # Try to get the templates from our CACHE.
     if ($this->templates = get_cached_item($server_id, $class['item'])) {
         if (DEBUG_ENABLED) {
             debug_log('Using CACHED templates', 4, 0, __FILE__, __LINE__, __METHOD__);
         }
         # See if the template_time has expired to see if we should reload the templates.
         foreach ($this->templates as $index => $template) {
             # If the file no longer exists, we'll delete the template.
             if (!file_exists($template->getFileName())) {
                 unset($this->templates[$index]);
                 $changed = true;
                 system_message(array('title' => _('Template XML file removed.'), 'body' => sprintf('%s %s (%s)', _('Template XML file has removed'), $template->getName(false), $template->getType()), 'type' => 'info', 'special' => true));
                 continue;
             }
             if ($template->getReadTime() < time() - $class['cachetime'] && filectime($template->getFileName()) > $template->getReadTime()) {
                 system_message(array('title' => _('Template XML file changed.'), 'body' => sprintf('%s %s (%s)', _('Template XML file has changed and been reread'), $template->getName(false), $template->getType()), 'type' => 'info', 'special' => true));
                 $changed = true;
                 eval(sprintf('$this->templates[$index] = new %s($this->server_id,$template->getName(false),$template->getFileName(),$template->getType(),$index);', $class['name']));
             }
         }
         if (DEBUG_ENABLED) {
             debug_log('Templates refreshed', 4, 0, __FILE__, __LINE__, __METHOD__);
         }
         # See if there are any new template files
         $index = max(array_keys($this->templates)) + 1;
         foreach ($class['types'] as $type) {
             $dir = $class['dir'] . $type;
             $dh = opendir($dir);
             if (!$type) {
                 $type = 'template';
             }
             while ($file = readdir($dh)) {
                 # Ignore any files that are not XML files.
                 if (!preg_match('/.xml$/', $file)) {
                     continue;
                 }
                 # Ignore any files that are not the predefined custom files.
                 if ($_SESSION[APPCONFIG]->getValue('appearance', 'custom_templates_only') && !preg_match("/^{$custom_prefix}/", $file)) {
                     continue;
                 }
                 $filename = sprintf('%s/%s', $dir, $file);
                 if (!in_array($filename, $this->getTemplateFiles())) {
                     $templatename = preg_replace('/.xml$/', '', $file);
                     eval(sprintf('$this->templates[$index] = new %s($this->server_id,$templatename,$filename,$type,$index);', $class['name']));
                     $index++;
                     $changed = true;
                     system_message(array('title' => _('New Template XML found.'), 'body' => sprintf('%s %s (%s)', _('A new template XML file has been loaded'), $file, $type), 'type' => 'info', 'special' => true));
                 }
             }
         }
     } else {
         if (DEBUG_ENABLED) {
             debug_log('Parsing templates', 4, 0, __FILE__, __LINE__, __METHOD__);
         }
         # Need to reset this, as get_cached_item() returns null if nothing cached.
         $this->templates = array();
         $changed = true;
         $counter = 0;
         foreach ($class['types'] as $type) {
             $dir = $class['dir'] . $type;
             $dh = opendir($class['dir'] . $type);
             if (!$type) {
                 $type = 'template';
             }
             while ($file = readdir($dh)) {
                 # Ignore any files that are not XML files.
                 if (!preg_match('/.xml$/', $file)) {
                     continue;
                 }
                 # Ignore any files that are not the predefined custom files.
                 if ($_SESSION[APPCONFIG]->getValue('appearance', 'custom_templates_only') && !preg_match("/^{$custom_prefix}/", $file)) {
                     continue;
                 }
                 $filename = sprintf('%s/%s', $dir, $file);
                 # Store the template
                 $templatename = preg_replace('/.xml$/', '', $file);
                 eval(sprintf('$this->templates[$counter] = new %s($this->server_id,$templatename,$filename,$type,$counter);', $class['name']));
                 $counter++;
             }
         }
     }
     if (DEBUG_ENABLED) {
         debug_log('Templates loaded', 4, 0, __FILE__, __LINE__, __METHOD__);
     }
     if ($changed) {
         masort($this->templates, 'title');
         set_cached_item($server_id, $class['item'], 'null', $this->templates);
     }
 }
 /**
  * Gets an array of AttributeType objects that entries of this ObjectClass may define.
  * This differs from getMayAttrNames in that it returns an array of AttributeType objects
  *
  * @param array $oclasses An array of ObjectClass objects to use when traversing
  *             the inheritance tree. This presents some what of a bootstrapping problem
  *             as we must fetch all objectClasses to determine through inheritance which
  *             attributes this objectClass provides.
  * @return array The array of allowed AttributeType objects.
  *
  * @see getMustAttrNames
  * @see getMustAttrs
  * @see getMayAttrNames
  * @see AttributeType
  */
 function getMayAttrs($oclasses = null)
 {
     if (DEBUG_ENABLED) {
         debug_log('%s::getMayAttrs(): Entered with (%s)', 9, get_class($this), $oclasses);
     }
     $all_may_attrs = array();
     $all_may_attrs = $this->may_attrs;
     foreach ($this->sup_classes as $sup_class_name) {
         if (!is_null($oclasses) && $sup_class_name != 'top' && isset($oclasses[strtolower($sup_class_name)])) {
             $sup_class = $oclasses[strtolower($sup_class_name)];
             $sup_class_may_attrs = $sup_class->getMayAttrs($oclasses);
             $all_may_attrs = array_merge($sup_class_may_attrs, $all_may_attrs);
         }
     }
     masort($all_may_attrs, 'name,source', 1);
     # Remove any duplicates
     foreach ($all_may_attrs as $index => $attr) {
         if (isset($allattr[$attr->name])) {
             unset($all_may_attrs[$index]);
         } else {
             $allattr[$attr->name] = 1;
         }
     }
     return $all_may_attrs;
 }
Example #11
0
 /**
  * Get available attributes
  */
 public function getAvailAttrs()
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     $attributes = array();
     $server = $this->getServer();
     # Initialise the Attribute Factory.
     $attribute_factory = new AttributeFactory();
     if (in_array_ignore_case('extensibleobject', $this->getObjectClasses())) {
         foreach ($server->SchemaAttributes() as $sattr) {
             $attribute = $attribute_factory->newAttribute($sattr->getName(), array('values' => array()), $server->getIndex(), null);
             array_push($attributes, $attribute);
         }
     } else {
         $attrs = array();
         foreach ($this->getObjectClasses() as $oc) {
             $soc = $server->getSchemaObjectClass($oc);
             $attrs = array_merge($attrs, $soc->getMustAttrNames(true), $soc->getMayAttrNames(true));
             $attrs = array_unique($attrs);
         }
         foreach ($attrs as $attr) {
             if (is_null($this->getAttribute($attr))) {
                 $attribute = $attribute_factory->newAttribute($attr, array('values' => array()), $server->getIndex(), null);
                 array_push($attributes, $attribute);
             }
         }
     }
     masort($attributes, 'name');
     return $attributes;
 }
    if ($_REQUEST['template'] == 'custom') {
        include TMPLDIR . 'template_header.php';
        require TMPLDIR . 'creation/custom.php';
        die;
    } else {
        $templates = new Templates($ldapserver->server_id);
        $template = $templates->GetTemplate($_REQUEST['template']);
    }
}
include TMPLDIR . 'template_header.php';
/*
 * When we get here, (either a new entry, or modifying an existing entry), if the
 * empty_attrs array has content, then we need to ask the user for this information.
 */
if (isset($template['empty_attrs'])) {
    masort($template['empty_attrs'], 'page,order', 1);
    # What page are we working on.
    $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
    printf('<center><h2>%s</h2></center>', $template['description']);
    echo "\n\n";
    if (isset($_REQUEST['nextpage']) && !$_REQUEST['nextpage']) {
        $new_dn = sprintf('%s=%s,%s', $template['rdn'], $_REQUEST['form'][$template['rdn']], $_REQUEST['container']);
        echo '<form action="create.php" method="post">';
        printf('<input type="hidden" name="new_dn" value="%s" />', $new_dn);
    } else {
        echo '<form action="template_engine.php" method="post" id="template_form" name="template_form" enctype="multipart/form-data">';
    }
    if (isset($_REQUEST['form'])) {
        foreach ($_REQUEST['form'] as $attr => $value) {
            # Check for any with post actions.
            if (isset($template['attribute'][$attr]['post']) && $_REQUEST['page'] == $template['attribute'][$attr]['page'] + 1) {