$exp1[0] ) return 1; if( $exp2[0] < $exp1[0] ) return -1; // Compare minor numbers if( $exp2[1] > $exp1[1] ) return 1; if( $exp2[1] < $exp1[1] ) return -1; // Compare patch level numbers if( $exp2[2] > $exp1[2] ) return 1; if( $exp2[2] < $exp1[2] ) return -1; return 0; } //******************** TIME FUNCTIONS // convert Time to Index function cTtI( $hour, $minute) { // Convert the hour minute combination to an index between 0 and 48 // (In a day we have 24 hours and we represent it in 48 half hours) $index = $hour * 2; if( $minute >= 30 ) $index += 1; return $index; } function convert_to_index( $unixtime ) { $hour = intval(date("H",$unixtime)); $minute = intval(date("i",$unixtime)); return cTtI($hour,$minute); } function getCurrentIndex() { $hour = date("G",time()); $min = date("i",time()); return cTtI(intval($hour),intval($min)); } function isToday( $unixTimeStamp ) { $day = date("j",$unixTimeStamp); $month = date("n",$unixTimeStamp); $year = date("Y",$unixTimeStamp); // print "(".$day."-".$month."-".$year.")"; $day2 = date("j",time()); $month2 = date("n",time()); $year2 = date("Y",time()); // print "(".$day2."-".$month2."-".$year2.")"; if( $day == $day2 && $month == $month2 && $year == $year2 ) return 1; else return 0; } function isWeekend( $wday ) { if ( $wday == 0 || $wday == 6 ) return true; else return false; } // convert Index to Time function cItT( $index) { $index = $index % 48; $time = "" . intval($index/2); if( $index % 2 ) $time .= ".30"; else $time .= ".00"; return $time; } function print_time( $time ) { global $force_time_format; $output = array(); // By default the preferred time format is detected using the // PHP strftime function and the %X switch. This can be overrided though switch($force_time_format) { case "standard": $time = strftime("%r",$time); break; case "military": $time = strftime("%R",$time); break; default: $time = strftime("%X",$time); } $time_arr = explode(" ",$time); foreach($time_arr as $element) { $exploded_element = explode(":",$element); // check if we have the hour,minute,sec representation seperated with doubledots if( count($exploded_element) == 3 ) { // Only show two elements $output[] = $exploded_element[0].":".$exploded_element[1]; } else { switch( $element ) { case "AM" : $output[] = "am"; break; case "PM" : $output[] = "pm"; break; default: $output[] = $element; } } } return implode(" ",$output); } function detect_time_representation() { // Depending on locale we determine the time representation format // Currently the default is the 24 hour support // Returns: 0 = 24 hour representation // 1 = 12 am/pm representation global $force_time_format; $time = mktime(); // By default the preferred time format is detected using the // PHP strftime function and the %X switch. This can be overrided though switch($force_time_format) { case "standard": $time = strftime("%r",$time); break; case "military": $time = strftime("%R",$time); break; default: $time = strftime("%X",$time); } $time_arr = explode(" ",$time); foreach($time_arr as $element) { switch( $element ) { case "AM" : case "PM" : return 1; } } return 0; } function print_date( $date ) { return strftime("%x",$date); } function get_week_nr( $date ) { // I never knew that calculating weeknumber can be so tricky... To get it all right // I read some official docs about ISO time and date stuff. Here is a description about // what the first week will be. // // In commercial and industrial applications (delivery times, production plans, etc.), // especially in Europe, it is often required to refer to a week of a year. Week 01 of // a year is per definition the first week that has the Thursday in this year, which // is equivalent to the week that contains the fourth day of January. In other words, // the first week of a new year is the week that has the majority of its days in the // new year. Week 01 might also contain days from the previous year and the week before // week 01 of a year is the last week (52 or 53) of the previous year even if it contains // days from the new year. A week starts with Monday (day 1) and ends with Sunday (day 7). // // I finally took some code from the Pear Date library. That is what Open Source is good // for. $day = date("j",$date); $month = date("n",$date); $year = date("Y",$date); return weekOfYear( $day, $month , $year ); /* $date_year = date("Y",$date); $first_year_week_day = date("w",mktime( 0,0,0,1,1,$date_year ) ); if( $first_year_week_day == 0 ) $first_year_week_day = 7; $first_year_week_day -= 1; return intval( ($first_year_week_day + date("z", $date )) / 7) + 1; */ } function print_duration( $start_time , $end_time ) { $duration = $end_time - $start_time; $hours = intval($duration / 3600) ; $rest = intval(($duration - ( $hours * 3600 )) / 60 ); return $hours."H ".$rest."m"; } // START: I lend some code from the PEAR Date 1.4.3 object, but I don't need all they have... /** * Returns the current local date. NOTE: This function * retrieves the local date using strftime(), which may * or may not be 32-bit safe on your system. * * @param string the strftime() format to return the date * * @access public * * @return string the current date in specified format */ function dateNow($format='%Y%m%d') { return(strftime($format,time())); } // end func dateNow /** * Returns true for a leap year, else false * * @param string year in format CCYY * * @access public * * @return boolean true/false */ function isLeapYear($year='') { if (empty($year)) { $year = dateNow('%Y'); } if (preg_match('/\D/',$year)) { return false; } if ($year < 1000) { return false; } if ($year < 1582) { // pre Gregorio XIII - 1582 return ($year % 4 == 0); } else { // post Gregorio XIII - 1582 return ( (($year % 4 == 0) and ($year % 100 != 0)) or ($year % 400 == 0) ); } } // end func isLeapYear /** * Converts from Gregorian Year-Month-Day to * ISO YearNumber-WeekNumber-WeekDay * * Uses ISO 8601 definitions. * Algorithm from Rick McCarty, 1999 at * http://personal.ecu.edu/mccartyr/ISOwdALG.txt * * @param string day in format DD * @param string month in format MM * @param string year in format CCYY * @return string * @access public */ // Transcribed to PHP by Jesus M. Castagnetto (blame him if it is fubared ;-) function gregorianToISO($day,$month,$year) { $mnth = array (0,31,59,90,120,151,181,212,243,273,304,334); $y_isleap = isLeapYear($year); $y_1_isleap = isLeapYear($year - 1); $day_of_year_number = $day + $mnth[$month - 1]; if ($y_isleap && $month > 2) { $day_of_year_number++; } // find Jan 1 weekday (monday = 1, sunday = 7) $yy = ($year - 1) % 100; $c = ($year - 1) - $yy; $g = $yy + intval($yy/4); $jan1_weekday = 1 + intval((((($c / 100) % 4) * 5) + $g) % 7); // weekday for year-month-day $h = $day_of_year_number + ($jan1_weekday - 1); $weekday = 1 + intval(($h - 1) % 7); // find if Y M D falls in YearNumber Y-1, WeekNumber 52 or if ($day_of_year_number <= (8 - $jan1_weekday) && $jan1_weekday > 4){ $yearnumber = $year - 1; if ($jan1_weekday == 5 || ($jan1_weekday == 6 && $y_1_isleap)) { $weeknumber = 53; } else { $weeknumber = 52; } } else { $yearnumber = $year; } // find if Y M D falls in YearNumber Y+1, WeekNumber 1 if ($yearnumber == $year) { if ($y_isleap) { $i = 366; } else { $i = 365; } if (($i - $day_of_year_number) < (4 - $weekday)) { $yearnumber++; $weeknumber = 1; } } // find if Y M D falls in YearNumber Y, WeekNumber 1 through 53 if ($yearnumber == $year) { $j = $day_of_year_number + (7 - $weekday) + ($jan1_weekday - 1); $weeknumber = intval($j / 7); if ($jan1_weekday > 4) { $weeknumber--; } } // put it all together if ($weeknumber < 10) $weeknumber = '0'.$weeknumber; return "{$yearnumber}-{$weeknumber}-{$weekday}"; } /** * Returns week of the year, first Sunday is first day of first week * * @param string day in format DD, default is current local day * @param string month in format MM, default is current local month * @param string year in format CCYY, default is current local year * * @access public * * @return integer $week_number */ function weekOfYear($day='',$month='',$year='') { if (empty($year)) { $year = dateNow('%Y'); } if (empty($month)) { $month = dateNow('%m'); } if (empty($day)) { $day = dateNow('%d'); } $iso = gregorianToISO($day, $month, $year); $parts = explode('-',$iso); $week_number = intval($parts[1]); return $week_number; } // end func weekOfYear // END: I lend some code from the PEAR Date object, but I don't need all they have... //********** APPOINTMENT FUNCTIONS function get_user_appointments( $user_id , $dayTime , $short) { // This is here for compliance to the adopted coding style return getUserAppointments( $user_id , $dayTime , $short ); } // Get meetings of persons on their ID for a certain date // $short is a flag which shows a special short description for // week and month overviews. function getUserAppointments( $user_id , $dayTime , $short ) { if( !isset($short) ) $short = 0; $appointments = array(); pbcs_db_connect (); pbcs_db_select_db(); $UID = getUIDfromSID($GLOBALS["SID"]); $date_start = mktime(0,0,0, date("m", $dayTime), date("d", $dayTime), date("Y", $dayTime)); $date_end = mktime(0,0,0, date("m", $dayTime), date("d", $dayTime)+1, date("Y", $dayTime)); // First find all Appointments for the User and let the database do all the work! $result = pbcs_db_query("SELECT B.* FROM ". "pbcs_join_table_user_app A, pbcs_appointment B WHERE ". "A.user_id = '$user_id' AND ". "B.id = A.appointment_id AND ". "B.is_note = 0 AND ". "B.start_time >= $date_start AND ". "B.start_time < $date_end ORDER BY B.start_time"); while ( $row = pbcs_db_fetch_row($result) ) { list($id, $start_time, $end_time , $description, $is_note , $private, $dummy, $AppointmentStatus, $allDay) = $row; // if the given user_id is not the session User we must // protect private appointments if ( $private == 1 && $user_id != $UID ) { $description = "Private appointment"; } else { // if a project is associated, plonk it in front of the appointment description. $result2 = pbcs_db_query("select project_id from pbcs_join_table_app_project where appointment_id = '$id'"); if ( $result2 ) { $row2 = pbcs_db_fetch_array($result2); if ( intval($row2[0]) != 0 ) { $result3 = pbcs_db_query("SELECT B.code FROM ". "pbcs_join_table_appointment_project A, pbcs_project B ". "WHERE A.appointment_id = '$id' AND ". "B.ID = A.appointment_id"); // okay, there was a matching row, retrieve the human readable // project code if ( $result3 ) { $row3 = pbcs_db_fetch_array($result3); $projectCode = $row3["code"]; if ( $projectCode != "" && $short != 1 ) $description = "(" . $projectCode . ") " . $description; } } } } $start_hour = intval(date("H",$start_time)); $start_minute = intval(date("i",$start_time)); $end_hour = intval(date("H",$end_time)); $end_minute = intval(date("i",$end_time)); $appointments[] = array( cTtI($start_hour,$start_minute), // [0] decimal start cTtI($end_hour, $end_minute), // [1] decimal end $description ,$id, $user_id, // [2] description, [3] appID, [4] userID $private, $AppointmentStatus, $allDay, // flags ([5] private, [6] appStatus, [7] allDay) $start_time,$end_time); // [8] start_time (unixtime) , [9] end_time (unixtime) } return $appointments; } function get_user_notes( $user_id , $dayTime ) { // This is here for compliance to the adopted coding style return getUserNotes( $user_id , $dayTime ); } function getUserNotes( $user_id , $dayTime ) { // Gives all notes for a user on a day. // returns: description, note id and the user_id $notes = array(); pbcs_db_connect (); pbcs_db_select_db(); $UID = getUIDfromSID($GLOBALS["SID"]); $date_start = mktime (0,0,0,date("m",$dayTime) ,date("d",$dayTime),date("Y",$dayTime)); $date_end = mktime (0,0,0,date("m",$dayTime) ,date("d",$dayTime)+1,date("Y",$dayTime)); // First find all Appointments for the User and let the database do all the work! $result = pbcs_db_query("SELECT B.* FROM ". "pbcs_join_table_user_app A, pbcs_appointment B WHERE ". "A.user_id = '$user_id' AND ". "B.id = A.appointment_id AND ". "B.is_note > 0 AND ". "B.start_time >= $date_start AND ". "B.start_time < $date_end ORDER BY B.start_time"); while( ($row = pbcs_db_fetch_row($result)) ) { list($id, $start_time, $end_time , $description, $is_note , $private, $dummy, $AppointmentStatus, $allDay) = $row; if( $private == 1 && $user_id != $UID ) { // if the given user_id is not the session User we must // protect private appointments $description = "Private note"; } $notes[] = array( $description , $id, $user_id , $private , $is_note, $start_time , $end_time ); } return $notes; } /* Notes have the following fields note[0] = description note[1] = note_id (= appointment_id) note[2] = user_id note[3] = private flag ( 1 = private ) note[4] = is_note flag ( 1 = note ) note[5] = start_time (unixtime) note[6] = end_time */ // This function is needed by sort_list function sort_compare($a, $b) { if (intval($a["start_time"]) == intval($b["start_time"])) return 0; return (intval($a["start_time"]) > intval($b["start_time"])) ? 1 : -1; } // This is a sort function to sort meetings on start time! // These meetings are returned by getUserAppointment // For use with multiple users you must add all appointments // seperately in an array (have a look at the list overview in day.php function sort_list( $meetings) { usort($meetings, 'sort_compare'); return $meetings; } //************************ HTML STUFF function js_show_title( $title ) { print "\n"; } function js_show_popup() { ?> " . $fullname . "'s Calendar - " . $viewtitle . ""; print ""; print ""; print ""; print ""; print "
".lang_get("User").": ".str_replace(" "," ",$fullname)." ".lang_get("Today").": ". strftime("%x" /* lang_get('time_fmt') */,time())."".lang_get('Week nr').": ".get_week_nr( time() )."
\n"; } function print_body($frame_name, $focus=false) { // This is the function that generates the PBCS specific BODY tag. // If you specify a frame_name then it is possible that you get specific // backgrounds for that frame you specified. // Optionally you can enable onLoad focus(), meaning that the window will pop-up // and get in front of the rest global $color, $background; $extra_stuff = ""; if( $focus ) $extra_stuff += " onLoad=\"focus();\" "; if( $background[$frame_name] ) print ""; else print ""; } function print_stylesheet() { global $pbcs_stylesheet; print ""; print ""; } function print_meta_refresh() { global $refresh_overviews; global $overview_refresh_time; global $REQUEST_URI; if( $refresh_overviews ) { print "\n"; } } function show_note( $the_note, $SID, $UID ) { // This function shows notes to the session user. // It will show Delete and Edit links for non-private notes // and for private notes that are owned by the session user // UID = the user ID of the note creator global $status_modification_protection; global $status_appointment_invisibility; global $show_icons; global $user_mkapp_mask; global $user_mkAllApp_mask; global $user_admin_mask; global $user_viewapp_mask; global $note_span_colors; // We need the status of the appointment User if( is_auth_level($user_viewapp_mask) ) { $AppStatus = getStatusFromUID( $the_note[2] ); $UIDStatus = getStatusFromUID( $UID ); } else { $AppStatus = 0; $UIDStatus = 0; } if ( is_auth_level($user_viewapp_mask)) { $show_editbar = false; if ( is_auth_level($user_mkapp_mask) && $UID == $the_note[2] ) $show_editbar = true; // print "UID: $UID
".$the_note[2]." - ".$the_note[3]."
"; // print ".. ".($UID != $the_note[2]?"true":"false")."
"; // print ".. ".((($UID != $the_note[2]) && $the_note[3] == 1)?"true":"false")."
"; if( $the_note[4] > 1 ) { print ''; print '"; } // This function shows appointments to the session user. // It will show Delete and Edit links for non-private appointments // and for private appointments that are owned by the session user /* appointment[0] starttime appointment[1] endtime appointment[2] description appointment[3] AppID appointment[4] UID appointment[5] private appointment[6] appointment status ( 0 = free, 1 = tentative, 2 = booked, etc) appointment[7] allDay */ function show_day_appointment( $the_appointment, $SID, $UID ) { /* Lets define all parameters to take into account when showing off appointments. USER SETTINGS: - Different handling for owned appointments and others (check UID) - is the appointment private - check the UID for a private appointment (show to owner only) - may the user create appointments for him/herself (user_mkapp_mask) - may the user create appointments for others (user_mkAllApp_mask) - GLOBAL SETTINGS: - show app header with colored bar - show icons or not - work in days This function returns a string representing the appointment. */ global $icon_edit_image,$icon_cant_edit_image; global $icon_delete_image,$icon_cant_delete_image; global $user_mkapp_mask; global $user_mkAllApp_mask; global $user_admin_mask; global $user_viewapp_mask; global $show_icons; global $work_in_days; global $color; global $show_apps_with_header; global $tmp_show_header_in_app,$tmp_SID,$tmp_UID; $AppStatus = getStatusFromUID( $the_appointment[4] ); $UIDStatus = getStatusFromUID( $UID ); $app_start_time = $the_appointment[8]; // Use Unix timestamped time! $app_end_time = $the_appointment[9]; // Use Unix timestamped time! $app_description = $the_appointment[2]; $app_id = $the_appointment[3]; $app_uid = $the_appointment[4]; $app_is_private = $the_appointment[5]; $app_status = $the_appointment[6]; $app_allday = $the_appointment[7]; // don't fetch the same data all the time if the UID and SID are the same if(! isset( $tmp_show_header_in_app ) || ( $SID != $tmp_SID && $UID != $tmp_UID ) ) { $tmp_show_header_in_app = pbcs_get_preference('show_header_in_app'); $tmp_SID = $SID; $tmp_UID = $UID; } $tmp = $tmp_show_header_in_app; switch( $tmp ) { case "no": $show_apps_with_header = false; break; case "yes": $show_apps_with_header = true; break; default: $show_apps_with_header = true; } // Define the color based on the appointment status $appoint_type = getAppointmentTypeFromAppID($app_status); $appoint_color = 13 + $appoint_type; $header_color_index = ($show_apps_with_header?5:$appoint_color); // Start the table for the appointment $s = '
Note:'; } else print '
Note:'; if ( is_auth_level($user_mkAllApp_mask) ) { $show_editbar = true; if( ($UID != $the_note[2] && $the_note[3] == 1) ) $show_editbar = false; } if( $show_editbar ) { $link = "note-form.php?AppointmentID=".$the_note[1]."&SID=".$SID."&UID=".$the_note[2]."&Del=1"; print ""; if( $show_icons ) print "\"".lang_get("Delete")."\""; else print lang_get('Delete').""; print ""; print " "; if( $show_icons ) print "\"".lang_get("Edit")."\"
"; else print lang_get('Edit')."
"; } else { if( $show_icons ) { print "\"".lang_get("CantDelete")."\" "; print "\"".lang_get("CantEdit")."\"
"; } else { print lang_get("CantDelete").' '.lang_get("CantEdit").'
'; } } } print "
"; // if ( $status_appointment_invisibility && is_auth_level($user_admin_mask) && // $AppStatus != $UIDStatus) // print lang_get("A note"); // else if( $the_note[4] > 1 ) print print_time($the_note[5])." - ".print_time($the_note[6])."
"; print nl2br(htmlspecialchars(stripslashes($the_note[0]))); } function show_week_note( $the_note, $SID, $UID ) { global $color; print "
"; show_note($the_note, $SID, $UID ); print "
'; // Handle owned appointments differently // Show header $s .= ''; $s .= ''; $appoint_type = getAppointmentTypeFromAppID($the_appointment[3]); $appoint_color = 13 + $appoint_type; $s .= ''; $s .= '
'; if ( ! $work_in_days ) { $start_hour = intval(date("H",$the_appointment[8])); $start_minute = intval(date("i",$the_appointment[8])); $end_hour = intval(date("H",$the_appointment[9])); $end_minute = intval(date("i",$the_appointment[9])); $s .= ''.print_time($the_appointment[8])." - ".print_time($the_appointment[9]); $s .= ''; } else { $s .= " "; } // show edit and delete and edit icons if: // - the user may edit appointments of their own UID if user_mkapp_mask is set // - it may edit other appointments (if non-private) // - it may edit private appointments if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) { $the_link = 'appointment-delete.php?AppointmentID='.$the_appointment[3] .'&SID='.$SID; $s .= ''; // Don't ask to delete an appointment if you get the choice to remove it later on. // onClick="return confirmLink(\'Are you really sure, you want to remove this appointment?\',\''.$the_link.'\',\'popup\')">'; } if ( $show_icons ) { if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) $s .= ''.lang_get('Delete').''; else $s .= ''.lang_get('CantDelete')."; } else { if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) $s .= lang_get('Delete'); else $s .= lang_get('CantDelete'); } if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) $s .= ''; $s .= ' '; if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) { $s .= ''; } if ( $show_icons ) { if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) $s .= ''.lang_get('Edit').''; else $s .= ''.lang_get('CantEdit').''; } else { if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) $s .= lang_get('Edit'); else $s .= lang_get('CantEdit'); } if ( ( is_auth_level($user_mkapp_mask) && ( $UID == $app_uid) ) || (is_auth_level($user_mkAllApp_mask) && $app_is_private != 1) ) $s .= ''; $s .= '
'; // If an appointment is private only show it to the owner. if( $UID != $app_uid && $app_is_private == 1) { $s .= lang_get('An appointment'); } else { $s .= nl2br(htmlspecialchars(stripslashes($the_appointment[2]))); // print out the description } $s .= '
'; return $s; } function show_week_appointment( $the_appointment , $SID, $UID ) { global $show_icons; global $user_mkapp_mask; global $user_mkAllApp_mask; global $user_admin_mask; global $user_viewapp_mask; global $work_in_days; global $color; global $show_apps_with_header; global $tmp_show_header_in_app,$tmp_SID,$tmp_UID; // We need the status of the appointment User if( $status_modification_protection ) { $AppStatus = getStatusFromUID( $the_appointment[4] ); $UIDStatus = getStatusFromUID( $UID ); } else { $AppStatus = 0; $UIDStatus = 0; } $appoint_color = 13 + $the_appointment[6]; print ""; // don't fetch the same data all the time if the UID and SID are the same if(! isset( $tmp_show_header_in_app ) || ( $SID != $tmp_SID && $UID != $tmp_UID ) ) { $tmp_show_header_in_app = pbcs_get_preference('show_header_in_app'); $tmp_SID = $SID; $tmp_UID = $UID; } $tmp = $tmp_show_header_in_app; switch( $tmp ) { case "no": $show_apps_with_header = false; break; case "yes": $show_apps_with_header = true; break; default: $show_apps_with_header = true; } $appoint_type = getAppointmentTypeFromAppID($the_appointment[3]); $appoint_color = 13 + $appoint_type; $header_color_index = ($show_apps_with_header?5:$appoint_color); print '
'; print show_day_appointment( $the_appointment, $SID, $UID ); print '
'; print ''; } function show_week_date( $timestamp ) { } function array_to_string( $members ) { $mem_nr = count($members); $output = ""; for( $index = 0 ; $index < $mem_nr ; $index++ ) { if( $index > 0 && $index < ($mem_nr -1 ) ) $output .= ", "; if( $index == ( $mem_nr - 1) && $mem_nr > 1) $output .= " ".lang_get('and')." "; $output .= $members[$index]; } return $output; } //*********************** DATABASE STUFF function getUIDfromSID( $SID ) { $result = pbcs_db_query("SELECT user_id FROM pbcs_session WHERE id = $SID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function getLoginFromUID( $UID ) { $result = pbcs_db_query("SELECT login FROM pbcs_user WHERE id = $UID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function getSelectedGroupFromUID( $UID ) { $result = pbcs_db_query("SELECT selected_group FROM pbcs_user WHERE id = $UID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function getSelectedGroupFromSID( $SID ) { $result = pbcs_db_query("SELECT A.selected_group FROM pbcs_user A, pbcs_session B WHERE A.id = B.user_id AND B.id = $SID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function setSelectedGroupFromUID( $UID , $group) { $result = pbcs_db_query("UPDATE pbcs_user SET selected_group = '$group' WHERE id = $UID"); if (is_array($result)) { $row = pbcs_db_fetch_row( $result ); return $row[0]; } else { return false; } } function getUIDFromLogin( $Login ) { $result = pbcs_db_query("SELECT id FROM pbcs_user WHERE login = '$Login'"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function getFullNameFromUID( $UID ) { $result = pbcs_db_query("SELECT name, surname FROM pbcs_user WHERE id = $UID"); $row = pbcs_db_fetch_row( $result ); return $row[0] ." ". $row[1]; } function getFullNameFromLogin( $Login ) { $result = pbcs_db_query("SELECT name, surname FROM pbcs_user WHERE login = '$Login'"); $row = pbcs_db_fetch_row( $result ); return $row[0] ." ". $row[1]; } function getStatusFromUID( $UID ) { $result = pbcs_db_query("SELECT status FROM pbcs_user WHERE id = $UID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function getAppointmentTypeFromAppID( $AppID ) { $result = pbcs_db_query("SELECT status FROM pbcs_appointment WHERE id = $AppID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function getLang_TZFromUID( $UID ) { $result = pbcs_db_query("SELECT timezone, language FROM pbcs_user WHERE id = $UID"); $row = pbcs_db_fetch_row( $result ); return array( $row[0] , $row[1]); } function getDefaultEmailFromUID( $UID ) { // Currently in v0.5 only one email address per user is supported. // The tables are created to support multiple addresses, but that requires // a more complex user interface $result = pbcs_db_query("SELECT email_address FROM pbcs_email_address WHERE user_id = $UID"); $row = pbcs_db_fetch_row( $result ); return $row[0]; } function get_formatted_name( $name, $surname_prefix, $surname , $formatted_name) { $f_name = ""; $format = explode('%',$formatted_name); foreach( $format as $option ) { if( $f_name != "" && $f_name[(count($f_name)-1)] != ' ' ) $f_name .= " "; switch( $option ) { case 's' : $f_name .= $surname; break; case 'S' : $f_name .= ucwords($surname); break; case 'p' : $f_name .= $surname_prefix; break; case 'P' : $f_name .= ucwords($surname_prefix); break; case 'j' : if( $surname_prefix == "" ) break; $initials = ""; $names = explode(' ',$surname_prefix); foreach( $names as $nam ) { $initials .= $nam[0]."."; } $f_name .= $initials; break; case 'n' : $f_name .= $name; break; case 'N' : $f_name .= ucwords($name); break; case 'I' : if( $name == "" ) break; $caps_initials = ""; $names = explode(' ',$name); foreach( $names as $nam ) { $caps_initials .= ucfirst($nam[0])."."; } $f_name .= $caps_initials; break; } } return $f_name; } function getFormattedName( $name, $surname_prefix, $surname ) { global $formatted_name; return get_formatted_name( $name , $surname_prefix, $surname , $formatted_name); } function getShortFormattedName( $name, $surname_prefix, $surname ) { global $short_formatted_name; return get_formatted_name( $name , $surname_prefix, $surname , $short_formatted_name); } function getGroupedUsers() { // This function returns a two-dimensional array with first index the // groupnames and as second index the users in that group. // The user information is an array with the following indexes: // 0 = ID // 1 = Name // 2 = SurnamePrefix // 3 = Surname // 4 = Status global $groups,$user_show_group_members,$SID; $UID = getUIDfromSID($SID); $group_array = array(); $result = pbcs_db_query("SELECT id, name, surname_prefix, surname, status FROM pbcs_user ORDER BY surname, name"); while ($row = pbcs_db_fetch_array( $result ) ) { if( $row['id'] == $UID ) $current_user = $row; foreach( $groups as $key => $group ) { if( $row['status'] & $key ) { $group_array[ $key ][] = $row; } } } // Do an extra check if a user may only see its own groups. if( is_auth_level( $user_show_group_members ) ) { $group_array2 = array(); foreach( $group_array as $group_arr => $value ) { if( $current_user['status'] & $group_arr) $group_array2[$group_arr] = $value; } $group_array = $group_array2; } return $group_array; } function getAllUsers() { // One dimensional array $users = array(); $result = pbcs_db_query("SELECT id, name, surname_prefix, surname, status FROM pbcs_user ORDER BY surname, name"); while ($row = pbcs_db_fetch_array( $result ) ) { $users[] = $row; } return $users; } function showGroupedUsers( $group_array ) { // This function is for debugging only global $groups; foreach( $groups as $key => $group ) { print "$group :
"; if( $group_array[$key] == 0 ) continue; foreach( $group_array[$key] as $member ) { print getFormattedname( $member[1], $member[2], $member[3] )."
"; } } } // LOG FUNCTIONS function do_log( $logfile , $logline ) { global $log_path; if( ! file_exists( $log_path ) ) { lang_show("log_path_nonexists");; exit; } $fp = fopen( $log_path.$logfile ,"a"); fputs($fp,date("r",time())." ".$logline."\n"); fclose($fp); } ?>