$title"; //}else{ $titlelink = "$title"; //} }else{ $titlelink = $title; } if ($session->logged_in){ $help_on = help_on($_SERVER["REQUEST_URI"]); if (has_help($help_on)){ $helplink = ""; }elseif ($session->isAdmin()){ $helplink = ""; } } print<< {$config['application_name']} Admin: $title {$config['application_name']} Admin

Home : $titlelink $helplink


EOF; } function admin_footer(){ global $session, $config; if ($session->logged_in){ print "
logged in as $session->username -- logout
Change Your Password or Email

© " . date("Y"). " Chicago Arts Partnerships in Education
"; }else{ print ""; } } function ulevel_name($ulevel){ global $config; switch ($ulevel){ case "9": return "Admin"; break; case "2": return $config['artist_name_uc']; break; case "1": return $config['editor_name_uc']; break; case "0": return "All User"; break; default: return "Error: Unknown Permissions"; } } function get_full_name($username){ global $session; $select = mysql_query("select firstname, lastname from users where username='$username'"); if ($row = mysql_fetch_array($select)){ return "{$row['firstname']} {$row['lastname']}"; } return ""; } function get_first_name($username){ global $session; $select = mysql_query("select firstname from users where username='$username'"); if ($row = mysql_fetch_array($select)){ return "{$row['firstname']}"; } return ""; } function get_title($id){ $select = mysql_query("select title from units where id='$id' limit 1"); if ($row = mysql_fetch_assoc($select)){ return $row['title']; }else{ return ""; } } function dbconnect($db){ global $config; $connect=mysql_pconnect($config['db_server'], $config['db_user'], $config['db_pass']); if (!$connect){ print "Can't connect to db"; } # if a db was specified, try and connect to it if (isset($db)){ $select = mysql_select_db($db); if ($select == 0){ print "Can't select db: $db"; } } } function school_select($unit_school){ global $config; $select = mysql_query("select schoolid, short_name from schools order by short_name"); $return = ""; return $return; } function nextcolor(){ global $i; if ($i == 0) { $i++; } else { $i--; } $colors = array ("#FFFFFF","#CCCCCC"); return $colors[$i]; } function bool_to_text($bool){ // make human readable Y/N if ($bool == 0 || $bool == 'N' || (!$bool)){ return "No"; }else{ return "Yes"; } } function admin_email(){ $select = mysql_query("select email from users where username='admin' limit 1"); if ($row = mysql_fetch_assoc($select)){ return $row['email']; }else{ print "error: can't find admin email!"; } } function help_on($url){ global $config; $parsed_url = parse_url($url); $help_url = $parsed_url['path']; $help_url = str_replace("{$config['install_path']}", "", $help_url); preg_match('/function\=(\w+)\&?/', $parsed_url['query'], $function); if ($function[1]){ $help_url .= "#$function[1]"; } return urlencode("$help_url"); } function has_help($help_on){ $help_on = urldecode($help_on); $select = mysql_query("select id from help where help_on='$help_on'"); if (mysql_num_rows($select) > 0){ return 1; }else{ return 0; } } function compute_bgcolor($color){ global $config; $color = strtoupper($color); // use lookup array first, then default to math $key = array_search($color, $config['colors']); if ($key > 0){ return $config['bgcolors'][$key]; } // math $color = preg_replace('/^#/','', $color); $r_delta = 95; $g_delta = 121; $b_delta = 180; $r = min((hexdec(substr($color, 0, 2)) + $r_delta), 255); $g = min((hexdec(substr($color, 2, 2)) + $g_delta), 255); $b = min((hexdec(substr($color, 4, 2)) + $b_delta), 255); return '#' . dechex($r) . dechex($g) . dechex($b); } function show_featured_teacher(){ $select = mysql_query("select user_bio as bio,username from users where user_bio != '' and user_picture='1' order by rand() limit 1"); if (mysql_num_rows($select) == 0){ return; } $row = mysql_fetch_array($select, MYSQL_ASSOC); print<<
Featured Teacher
{$row['bio']}
EOF; } function show_events(){ $select = mysql_query("select title, events_categories.category as category, location, description, date as datestamp, date_format(date, '%M %e') as date, date_format(date, '%l:%i %p') as time, date_format(end_date, '%M %e') as end_date, date_format(end_date, '%l:%i %p') as end_time, url from events, events_categories where events.category=events_categories.id and ( date > (current_date() - 1) or end_date > ( current_date() - 1)) order by category, datestamp asc"); print '
Events
'; if (mysql_num_rows($select) == 0){ print "

No events currently listed

"; } $current_category = ''; while ($row = mysql_fetch_array($select)){ if ($current_category != $row['category']){ print "

{$row['category']}

"; } $current_category = $row['category']; $event_dates = ''; if ($row['time'] != '12:00 AM'){ $event_dates = $row['date'] . " " . $row['time']; }else{ $event_dates = $row['date']; } // only show end date if it's not 0 if ($row['end_date']){ // don't show the to date if it's the same day $event_dates .= " to"; if ($row['end_date'] != $row['date']){ $event_dates .= " {$row['end_date']}"; } if ($row['end_time'] != '12:00 AM'){ $event_dates .= " {$row['end_time']}"; } } $row['url'] = preg_replace('/^http:\/\//', '', $row['url']); $row['url'] = "http://" . $row['url']; print "
"; print "

{$row['title']}

\n"; print "

{$row['description']}

\n"; print "

$event_dates

\n"; print "

{$row['location']}

\n"; print "
"; } print '
'; } function user_thumbnail($uname){ global $config, $picture; $picture_size = $_FILES['picture']['size']; if ($picture_size > 0){ //$run_identify = "identify -format \"%m %w %h\" \"{$_FILES['picture']['tmp_name']}\""; //$identify_output = `$run_identify`; //$picture_info = preg_split("/\s/",$identify_output); $picture_path = $config['install_full_path']."/images/user_" . $uname; $thumb_path = $config['install_full_path']."/images/userthumb_" . $uname; if (!move_uploaded_file($picture, $picture_path)){ print "can't move in uploaded file
"; return 0; } chmod($picture_path, 0664); if (!copy($picture_path, $thumb_path)){ print "failed to copy to thumb
"; return 0; } $run_thumb = "mogrify -geometry {$config['profile_picture_size']} -format jpg -sharpen 1x1 -gravity center -crop {$config['profile_picture_size']}+0+0 -quality 85 \"$thumb_path\""; $thumb_output = `$run_thumb`; return 1; }else{ return 0; } } function list_surveys(){ // from phpQ index.php $qstring = 'SELECT *, UNIX_TIMESTAMP() AS unw, UNIX_TIMESTAMP(StartDate) AS usd, UNIX_TIMESTAMP(EndDate) AS ued ' . 'FROM phpQSurvey WHERE Active="y" ORDER BY Active, Name'; $mqsurvey = mysql_query($qstring); while ($masurvey = mysql_fetch_array($mqsurvey)) { $validtime = true; $validtime = (substr($masurvey['StartDate'],0,10) != '0000-00-00') ? (($masurvey['unw'] >= $masurvey['usd']) ? $validtime: false) : $validtime; $validtime = (substr($masurvey['EndDate'],0,10) != '0000-00-00') ? (($masurvey['unw'] <= $masurvey['ued']) ? $validtime : false) : $validtime; if ($validtime) { $responseloc = ''; if ($masurvey['SurveyResults']) { $mqresponse = mysql_query(sprintf('SELECT COUNT(*) AS ct FROM phpQUser WHERE SID="%s"', $masurvey['SID'])); $responsect = 0; if ($maresponse = mysql_fetch_array($mqresponse)) { $responsect = $maresponse['ct']; } $responsemsg = ($responsect == 1) ? $phpQlang['response'] : $phpQlang['responses']; $responsemsg = sprintf($responsemsg, $responsect); $responseloc = sprintf('(%s)', $masurvey['SID'], $responsemsg); } $sid = $masurvey['SID']; $lnkstyle = ' class="link"'; $svname = $masurvey['Name']; $svname = (strlen($svname) > 50) ? substr($svname,0,50) . '...' : $svname; //$contents .= sprintf('--', $sid, $lnkstyle); $contents .= sprintf('
  • %s %s', $sid, $lnkstyle, $svname, $responseloc); if ($masurvey['Description']) { $contents .= sprintf('
    %s', $masurvey['Description']); } $contents .= '
  • '; } } return $contents; } function process_template($page, $mode){ global $elements, $id, $skip, $config; $default_content = $config['default_content']; if ($mode == 'edit'){ $cachebuster = '?cb='. microtime(); $elements['page'] = 'edit_units.php?function=edit&'; }else{ $elements['page'] = 'view_units.php?'; } // icon placeholder if (empty($elements['icon'])){ $elements['icon'] = '145x87 icon'; }else{ $elements['icon'] = ""; } if ($page == 'home'){ $templatefile = "templates/$page.html"; }else{ $templatefile = "templates/interior.html"; } if (!file_exists($templatefile)){ return "no template file found: $templatefile"; exit; } $template= file("$templatefile"); $templatecontent = ''; // fields that support newlines $elements['subtitle'] = str_replace("\n", "
    ", $elements['subtitle']); // tabs $tabs = array();; for ($i=1; $i<=$config['max_tabs']; $i++){ if (!empty($elements['tab'.$i.'_name'])){ // multi-d array with tab info [name, color, content, rollover] $tabs['tab'.$i.'_name'] = array( "name" => $elements['tab'.$i.'_name'], "color" => $elements['tab'.$i.'_color'], "content_bgcolor" => $elements['tab'.$i.'_content_bgcolor'], "column_type" => $elements['tab'.$i.'_content_type'], "content" => $elements['tab'.$i.'_content'], "rollover" => $elements['tab'.$i.'_rollover'] ); } } // determine tab padding if necc. $tab_width = floor(($config['width'] - 2) / count($tabs)); if ($config['max_tab_width']){ $max_tab_width = $config['max_tab_width']; }else{ $max_tab_width = 200; } if ($tab_width > $max_tab_width){ $outside_tab_padding = ($config['width'] - (count($tabs) * $max_tab_width)) / 2; }else{ $outside_tab_padding = $config['tab_padding']; } $tab_padding = $config['tab_padding']; // iterate through available tabs $i=0; foreach($tabs as $key=>$tab_array){ $i++; $tab_array['name'] = str_replace("\n", "
    ", $tab_array['name']); // pass tabs like "tab1", not "tab1_name" $key = str_replace("_name", "", $key); // extra padding on the first & last tab if (($i == 1) && ($config['first_tab_padding'])){ $elements['tabs'] .= ''; } $elements['tabs'] .= ' |"; $elements['image_tabs'] .= ""; }else{ if ($config['tab'.$i.'_highlighted']){ $current_tab_color = $tab_array['color']; }elseif ($config['tab_color']){ $current_tab_color = $config['tab_color']; } $elements['footer_links'] .= " [" . strtolower($tab_array['name']) . "] |"; $elements['image_tabs'] .= ""; } $elements['tabs'] .= " bgcolor=\"{$current_tab_color}\""; $elements['tabs'] .= ">\n"; // link $elements['tabs'] .= "{$tab_array['name']}"; if ($i < count($tabs)){ $elements['tabs'] .= ''; }else if (($i == count($tabs)) && ($config['first_tab_padding'])){ $elements['tabs'] .= ''; } } $elements['footer_links'] = preg_replace("/\s*\|$/", "", $elements['footer_links']); $elements['page_key'] = $page; // pagination $breaker_regex = '
    .*?<\/span><\/div>'; // main _content column controls how many pages there are, but images column follow suit. $pages = preg_split("/$breaker_regex/i", $elements[$page."_content"]); $pagecount = count($pages); $images_pages = preg_split("/$breaker_regex/i", $elements[$page."_image_content"]); // RAVINIA hard-code for process page if (($page=='tab5') && preg_match('/ravinia/i', $config['application_name'])){ if ($skip < 2){ $elements['tab5_column_type'] = 1; } // push first image column forward one page array_unshift($images_pages, ''); } //END RAVINIA hard-code if ($skip == 0){ $skip = 1; } if ($pagecount > 1){ $elements[$page."_content"] = $pages[$skip-1]; $elements[$page."_image_content"] = $images_pages[$skip-1]; $pagination = '
    Page:      '; for ($i=1; $i<=$pagecount; $i++){ $pagination .= '      '; if ($skip == $i){ $pagination .= $i; }else{ // this global mucked with in edit_units for change_tab_setup. $url = $_SERVER['REQUEST_URI']; $url = preg_replace('/&skip=\d+/', '', $url); $pagination .= "$i"; } } $pagination .= "
    "; $elements['pagination'] = $pagination; } while (list ($line_num, $line) = each ($template)) { $templatecontent .= "$line"; if (DEBUG > 1){ echo "Line $line_num: " . htmlspecialchars($line) . "
    \n"; } } // setup columns by doing a pre-search & replace on the template before all the other work. $main_content = ''; if ($elements[$page.'_column_type'] == "1"){ // left + right + padding // left column is the only column $left_column_width = $config['left_column'] + $config['right_column'] + 40; $main_content .= "%%content%%\n"; }else{ // 2 columns, need to get width if ($elements[$page.'_column_type'] == "2"){ $left_column_width = floor(($config['left_column'] + $config['right_column'])/2); $right_column_width = $left_column_width; }else if ($elements[$page.'_column_type'] == "3"){ // reverse of default $left_column_width = $config['right_column']; $right_column_width = $config['left_column']; }else{ // default $left_column_width = $config['left_column']; $right_column_width = $config['right_column']; } $main_content .= "%%content%%\n"; $main_content .= ''; $main_content .= "%%image_content%%"; } $main_content .= ''; $templatecontent = str_replace("%%main_content%%", $main_content, $templatecontent); // image content column is the narrower column // default content if ($mode == "edit"){ if (empty($elements[$page."_content"])){ if ($page != 'home'){ $elements[$page."_content"] = (empty($default_content[$page]) ? $default_content['interior'] : $default_content[$page]) . "

    Please add text or any image (maximum width " . max($left_column_width, $right_column_width) . " pixels)"; }else{ $elements[$page."_content"] = $default_content[$page]; } } if (empty($elements[$page."_image_content"])){ $elements[$page."_image_content"] = (empty($default_content[$page."_image"]) ? $default_content['image'] : $default_content[$page."_image"]) . "

    Please add any image (maximum width " . min($left_column_width, $right_column_width) . " pixels) or text"; } } // create long version of teachers' names $teachers_array = preg_split("/,\s?/", $elements['teachers']); $teachers_in = "'" . join("','", $teachers_array) . "'"; //foreach ($teachers_array as $teacher){ $teacher_select = mysql_query("select firstname, lastname, user_description, userlevel, user_type from users where username in ($teachers_in) order by userlevel desc, lastname"); while ($teacher_row = mysql_fetch_array($teacher_select, MYSQL_ASSOC)){ if ($teacher_row['user_type'] != ''){ $elements['teachers_long'] .= "
    {$teacher_row['user_type']}:
    "; } $elements['teachers_long'] .= "{$teacher_row['firstname']} {$teacher_row['lastname']}"; if ($teacher_row['user_description']){ $elements['teachers_long'] .= ", {$teacher_row['user_description']}"; } $elements['teachers_long'] .= "
    "; } $uneditable_tags = array('id', 'page', 'long_name', 'pagination', 'tabs', 'tab_rollover', 'tab_rollover_color', 'content_bgcolor', 'html_title', 'date_created', 'date_modified', 'modified_by', 'city', 'state', 'custom_field_1', 'custom_field_2', 'sponsored_by', 'image_tabs', 'footer_links', 'active_tab_color', 'page_key', 'teachers_long'); if (is_array($config['categories'])){ array_push($uneditable_tags, 'category'); } $uneditable_tags_regex = implode("|", $uneditable_tags); if ($mode == 'edit'){ $editlink = "
    " . "[edit]
    "; // non-editable tags $templatecontent = preg_replace("/%%(?!id%)(?!$uneditable_tags_regex)(\w*?)%%/","%%$1%%$editlink", $templatecontent); } // fix to handle use of editable tags in the HTML title field $elements['html_title'] = "{$config['application_name']}: {$elements['short_name']}"; $elements['content'] = $elements[$page."_content"]; $elements['image_content'] = $elements[$page."_image_content"]; // custome mienc code if (($elements['custom_field_1'] != 'None') || ($elements['custom_field_2'] != 'None')){ $elements['sponsored_by'] = "Site sponsored by "; if ($elements['custom_field_1'] != 'None'){ $elements['sponsored_by'] .= $elements['custom_field_1']; $sponsor_one = true; } if ($elements['custom_field_2'] != 'None'){ if ($sponsor_one){ $elements['sponsored_by'] .= " and "; } $elements['sponsored_by'] .= $elements['custom_field_2']; } } // end custom mienc code foreach ($elements as $elements_key => $elements_val){ // format date fields, any field with date in it. if (stristr($elements_key, "date")){ if (strtotime(substr($elements_val,0,8)) > 0){ $elements_val = strftime("%m/%d/%Y", strtotime(substr($elements_val,0,8))); }else{ // TODO add error logging } } if ($mode == 'edit'){ if (!in_array($elements_key, $uneditable_tags)){ if (preg_match('/icon|description|content$/',$elements_key)){ $div_style = 'block'; }else{ $div_style = 'inline'; } // placeholder if (!$elements_val){ $elements_val = "($elements_key)"; } $elements_val = "
    $elements_val
    "; } } $templatecontent = str_replace("%%$elements_key%%","$elements_val", $templatecontent); } // remove any leftover %% tags just in case $templatecontent = preg_replace("/%%\S+%%/","", $templatecontent); if ($mode == "edit"){ // try to stop image caching for edit mode $templatecontent = preg_replace("/src\=\"?(\/uploads\/.+?\.(?:jpg|gif|png))\"?/i", "src=\"$1$cachebuster\"", $templatecontent); } return $templatecontent; } ?>