コード例 #1
0
ファイル: cms_include_old.php プロジェクト: Redlord1977/oocms
function getRemoteTime($originTime, $remote_tz, $origin_tz)
{
    //convert origin time to UNIX time
    $unixTimeOrigin = strtotime($originTime);
    $offset = get_timezone_offset($remote_tz, $origin_tz);
    //echo "<br>$offset<br>";
    $unixRemoteTime = $unixTimeOrigin - $offset;
    //return time at remote office
    $remoteTime = date('M d H:i', $unixRemoteTime);
    return $remoteTime;
}
コード例 #2
0
ファイル: lib.global.php プロジェクト: baki250/angular-io-app
function get_timestamp($tz, $timestamp)
{
    $offset = get_timezone_offset($tz, $timestamp);
    $timestamp -= $offset;
    return $timestamp;
}
コード例 #3
0
/**
 * Parses a VEVENT into an array with fields.
 * 
 * @param vevent VEVENT.
 * @param dateFormat dateformat for displaying the start and end date. 
 * 
 * @return array().
 */
function parse_vevent($vevent, $dateFormat = "%Y-%m-%d", $timeFormat = "%H:%M")
{
    // Regex for the different fields
    $regex_summary = '/SUMMARY:(.*?)\\n/';
    $regex_location = '/LOCATION:(.*?)\\n/';
    // descriptions may be continued with a space at the start of the next line
    // BUGFIX: OR descriptions can be the last item in the VEVENT string
    $regex_description = '/DESCRIPTION:(.*?)\\n([^ ]|$)/s';
    // normal events with time
    $regex_dtstart = '/DTSTART.*?:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})/';
    $regex_dtend = '/DTEND.*?:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})/';
    // Timezones can be passed for individual dtstart and dtend by the ics
    $regex_dtstart_timezone = '/DTSTART;TZID=(.*?):([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})/';
    $regex_dtend_timezone = '/DTEND;TZID=(.*?):([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})/';
    // all day event
    $regex_alldaystart = '/DTSTART;VALUE=DATE:([0-9]{4})([0-9]{2})([0-9]{2})/';
    $regex_alldayend = '/DTEND;VALUE=DATE:([0-9]{4})([0-9]{2})([0-9]{2})/';
    // Make the entry
    $entry = array();
    $entry['vevent'] = "BEGIN:VEVENT\r\n" . $vevent . "END:VEVENT\r\n";
    // Get the summary
    if (preg_match($regex_summary, $vevent, $summary)) {
        $entry['summary'] = str_replace('\\,', ',', $summary[1]);
    }
    // Get the starting time timezone
    if (preg_match($regex_dtstart_timezone, $vevent, $timezone)) {
        $start_timezone = $timezone[1];
    } else {
        $start_timezone = 'UTC';
    }
    // Get the end time timezone
    if (preg_match($regex_dtend_timezone, $vevent, $timezone)) {
        $end_timezone = $timezone[1];
    } else {
        $end_timezone = 'UTC';
    }
    // Get the start and end times
    if (preg_match($regex_dtstart, $vevent, $dtstart)) {
        #                                hour          minute       second       month        day          year
        $entry['startunixdate'] = mktime($dtstart[4], $dtstart[5], $dtstart[6], $dtstart[2], $dtstart[3], $dtstart[1]);
        #Calculate the timezone offset
        $start_timeOffset = get_timezone_offset($start_timezone, $entry['startunixdate']);
        $entry['startunixdate'] = $entry['startunixdate'] + $start_timeOffset;
        $entry['startdate'] = strftime($dateFormat, $entry['startunixdate']);
        $entry['starttime'] = strftime($timeFormat, $entry['startunixdate']);
        preg_match($regex_dtend, $vevent, $dtend);
        $entry['endunixdate'] = mktime($dtend[4], $dtend[5], $dtend[6], $dtend[2], $dtend[3], $dtend[1]) + $timeOffset;
        $end_timeOffset = get_timezone_offset($end_timezone, $entry['endunixdate']);
        $entry['endunixdate'] = $entry['endunixdate'] + $end_timeOffset;
        $entry['enddate'] = strftime($dateFormat, $entry['endunixdate']);
        $entry['endtime'] = strftime($timeFormat, $entry['endunixdate']);
        $entry['allday'] = false;
    }
    if (preg_match($regex_alldaystart, $vevent, $alldaystart)) {
        $entry['startunixdate'] = mktime(0, 0, 0, $alldaystart[2], $alldaystart[3], $alldaystart[1]);
        # Calculate the timezone offset
        $start_timeOffset = get_timezone_offset($start_timezone, $entry['startunixdate']);
        $entry['startunixdate'] = $entry['startunixdate'] + $start_timeOffset;
        $entry['startdate'] = strftime($dateFormat, $entry['startunixdate']);
        preg_match($regex_alldayend, $vevent, $alldayend);
        $entry['endunixdate'] = mktime(0, 0, 0, $alldayend[2], $alldayend[3], $alldayend[1]);
        $end_timeOffset = get_timezone_offset($end_timezone, $entry['endunixdate']);
        $entry['endunixdate'] = $entry['endunixdate'] + $end_timeOffset - 1;
        $entry['enddate'] = strftime($dateFormat, $entry['endunixdate']);
        $entry['allday'] = true;
    }
    # also filter PalmPilot internal stuff
    if (preg_match('/@@@/', $entry['description'])) {
        continue;
    }
    if (preg_match($regex_description, $vevent, $description)) {
        $entry['description'] = $description[1];
        $entry['description'] = preg_replace("/[\r\n] ?/", "", $entry['description']);
        $entry['description'] = str_replace('\\,', ',', $entry['description']);
    }
    if (preg_match($regex_location, $vevent, $location)) {
        $entry['location'] = str_replace('\\,', ',', $location[1]);
    }
    return $entry;
}
コード例 #4
0
ファイル: send_event.php プロジェクト: eguicciardi/ada
    $event_time = today_timeFN();
} else {
    $event_time = $ora_evento;
}
if (!isset($data_evento)) {
    $event_date = today_dateFN();
} else {
    $event_date = $data_evento;
}
/*
$event_time = today_timeFN();
$event_date = today_dateFN();
*/
$ada_address_book = EventsAddressBook::create($userObj);
$tester_TimeZone = MultiPort::getTesterTimeZone($sess_selected_tester);
$time = time() + get_timezone_offset($tester_TimeZone, SERVER_TIMEZONE);
/*
* Last access link
*/
if (isset($_SESSION['sess_id_course_instance'])) {
    $last_access = $userObj->get_last_accessFN($_SESSION['sess_id_course_instance'], "UT", null);
    $last_access = AMA_DataHandler::ts_to_date($last_access);
} else {
    $last_access = $userObj->get_last_accessFN(null, "UT", null);
    $last_access = AMA_DataHandler::ts_to_date($last_access);
}
if ($last_access == '' || is_null($last_access)) {
    $last_access = '-';
}
$content_dataAr = array('user_name' => $user_name, 'user_type' => $user_type, 'user_level' => $user_level, 'titolo' => $titolo, 'testo' => isset($testo) ? trim($testo) : '', 'destinatari' => isset($destinatari) ? trim($destinatari) : '', 'course_title' => '<a href="../browsing/main_index.php">' . $course_title . '</a>', 'status' => $err_msg, 'timezone' => $tester_TimeZone, 'event_time' => $event_time, 'event_date' => $event_date, 'last_visit' => $last_access, 'rubrica' => $ada_address_book->getHtml(), 'status' => $err_msg);
$options_Ar = array('onload_func' => "load_addressbook();updateClock({$time});");
コード例 #5
0
ファイル: statslib.php プロジェクト: vinoth4891/clinique
/**
 * Start of month
 * @param int $time timestamp
 * @return start of month
 */
function stats_get_base_monthly($time = 0)
{
    global $CFG;
    if (empty($time)) {
        $time = time();
    }
    if ($CFG->timezone == 99) {
        return strtotime(date('1-M-Y', $time));
    } else {
        $time = stats_get_base_daily($time);
        $offset = get_timezone_offset($CFG->timezone);
        $gtime = $time + $offset;
        $day = gmdate('d', $gtime);
        if ($day == 1) {
            return $time;
        }
        return $gtime - ($day - 1) * 60 * 60 * 24;
    }
}
コード例 #6
0
 public function test_get_timezone_offset()
 {
     // This is a useless function, the timezone offset may be changing!
     $this->assertSame(60 * 60 * -5, get_timezone_offset('America/New_York'));
     $this->assertDebuggingCalled();
     $this->assertSame(60 * 60 * -1, get_timezone_offset(-1));
     $this->assertSame(60 * 60 * 1, get_timezone_offset(1));
     $this->assertSame(60 * 60 * 1, get_timezone_offset('Europe/Prague'));
     $this->assertSame(60 * 60 * 8, get_timezone_offset('Australia/Perth'));
     $this->assertSame(60 * 60 * 12, get_timezone_offset('Pacific/Auckland'));
     // Known half an hour offsets.
     $this->assertEquals(60 * 60 * -4.5, get_timezone_offset('-4.5'));
     $this->assertEquals(60 * 60 * -4.5, get_timezone_offset('America/Caracas'));
     $this->assertEquals(60 * 60 * 4.5, get_timezone_offset('4.5'));
     $this->assertEquals(60 * 60 * 4.5, get_timezone_offset('Asia/Kabul'));
     $this->assertEquals(60 * 60 * 5.5, get_timezone_offset('5.5'));
     $this->assertEquals(60 * 60 * 5.5, get_timezone_offset('Asia/Kolkata'));
     $this->assertEquals(60 * 60 * 6.5, get_timezone_offset('6.5'));
     $this->assertEquals(60 * 60 * 6.5, get_timezone_offset('Asia/Rangoon'));
     $this->assertEquals(60 * 60 * 9.5, get_timezone_offset('9.5'));
     $this->assertEquals(60 * 60 * 9.5, get_timezone_offset('Australia/Darwin'));
     $this->assertEquals(60 * 60 * 11.5, get_timezone_offset('11.5'));
     $this->assertEquals(60 * 60 * 11.5, get_timezone_offset('Pacific/Norfolk'));
     $this->resetDebugging();
 }
コード例 #7
0
function timezone_offset($zones)
{
    return get_timezone_offset($zones);
}
コード例 #8
0
 /**
  * Test the temporary table creation and deletion.
  *
  * @depends test_statslib_temp_table_create_and_drop
  */
 public function test_statslib_temp_table_fill()
 {
     global $CFG, $DB, $USER;
     $dataset = $this->load_xml_data_file(__DIR__ . "/fixtures/statslib-test09.xml");
     $this->prepare_db($dataset[0], array('log'));
     $start = self::DAY - get_timezone_offset($CFG->timezone);
     $end = $start + 24 * 3600;
     stats_temp_table_create();
     stats_temp_table_fill($start, $end);
     $this->assertEquals(1, $DB->count_records('temp_log1'));
     $this->assertEquals(1, $DB->count_records('temp_log2'));
     stats_temp_table_drop();
     // New log stores.
     $this->preventResetByRollback();
     stats_temp_table_create();
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     $fcontext = context_course::instance(SITEID);
     $user = $this->getDataGenerator()->create_user();
     $this->setUser($user);
     $this->assertFileExists("{$CFG->dirroot}/{$CFG->admin}/tool/log/store/standard/version.php");
     set_config('enabled_stores', 'logstore_standard', 'tool_log');
     set_config('buffersize', 0, 'logstore_standard');
     set_config('logguests', 1, 'logstore_standard');
     get_log_manager(true);
     $DB->delete_records('logstore_standard_log');
     \core_tests\event\create_executed::create(array('context' => $fcontext, 'courseid' => SITEID))->trigger();
     \core_tests\event\read_executed::create(array('context' => $context, 'courseid' => $course->id))->trigger();
     \core_tests\event\update_executed::create(array('context' => context_system::instance()))->trigger();
     \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
     \core\event\user_loggedin::create(array('userid' => $USER->id, 'objectid' => $USER->id, 'other' => array('username' => $USER->username)))->trigger();
     $DB->set_field('logstore_standard_log', 'timecreated', 10);
     $this->assertEquals(5, $DB->count_records('logstore_standard_log'));
     \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
     \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
     // Fake the origin of events.
     $DB->set_field('logstore_standard_log', 'origin', 'web', array());
     $this->assertEquals(7, $DB->count_records('logstore_standard_log'));
     stats_temp_table_fill(9, 11);
     $logs1 = $DB->get_records('temp_log1');
     $logs2 = $DB->get_records('temp_log2');
     $this->assertCount(5, $logs1);
     $this->assertCount(5, $logs2);
     // The order of records in the temp tables is not guaranteed...
     $viewcount = 0;
     $updatecount = 0;
     $logincount = 0;
     foreach ($logs1 as $log) {
         if ($log->course == $course->id) {
             $this->assertEquals('view', $log->action);
             $viewcount++;
         } else {
             $this->assertTrue(in_array($log->action, array('update', 'login')));
             if ($log->action === 'update') {
                 $updatecount++;
             } else {
                 $logincount++;
             }
             $this->assertEquals(SITEID, $log->course);
         }
         $this->assertEquals($user->id, $log->userid);
     }
     $this->assertEquals(1, $viewcount);
     $this->assertEquals(3, $updatecount);
     $this->assertEquals(1, $logincount);
     set_config('enabled_stores', '', 'tool_log');
     get_log_manager(true);
     stats_temp_table_drop();
 }
コード例 #9
0
function printSfiCalendar($userName, $pass, $ownerId, $baseUrl, $showDetail)
{
    function calguid($str)
    {
        $charid = strtoupper(md5($str));
        $hyphen = chr(45);
        // "-"
        $uuid = "" . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12);
        return $uuid;
    }
    function get_timezone_offset($remote_tz, $origin_tz = null)
    {
        if ($origin_tz === null) {
            if (!is_string($origin_tz = date_default_timezone_get())) {
                return false;
                // A UTC timestamp was returned -- bail out!
            }
        }
        $origin_dtz = new DateTimeZone($origin_tz);
        $remote_dtz = new DateTimeZone($remote_tz);
        $origin_dt = new DateTime("now", $origin_dtz);
        $remote_dt = new DateTime("now", $remote_dtz);
        $offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt);
        return $offset;
    }
    function escapeText($s)
    {
        $v = str_replace("\r\n", "\n", $s);
        $v = str_replace("\r", "\n", $s);
        $v = str_replace("\t", " ", $v);
        $v = str_replace("\v", " ", $v);
        $v = str_replace("\\", "\\\\", $v);
        $v = str_replace("\n", "\\n", $v);
        $v = str_replace(";", "\\;", $v);
        $v = str_replace(",", "\\,", $v);
        return $v;
    }
    try {
        $calGuid = calguid($userName . $ownerId);
        $mySforceConnection = new SforceEnterpriseClient();
        $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR . '/enterprise.wsdl.xml');
        $mylogin = $mySforceConnection->login($userName, $pass);
        $nowDate = new DateTime();
        $startDate = clone $nowDate;
        $startDate = $startDate->sub(new DateInterval('P366D'));
        $endDate = clone $nowDate;
        $endDate = $endDate->add(new DateInterval('P400D'));
        $query = 'SELECT Id, Name, TimeZoneSidKey from User where Id = \'' . $ownerId . '\'';
        $users = $mySforceConnection->query($query);
        if (count($users->records) == 0) {
            header('HTTP/1.1 403 Forbidden');
            echo 'no data';
            exit;
        }
        $query = '
SELECT
   Id
 , Subject
 , ActivityDateTime
 , StartDateTime
 , EndDateTime
 , Location ' . ($showDetail ? ' , Description ' : '') . '
 , IsAllDayEvent
 , OwnerId
from Event
where
      OwnerId = \'' . $ownerId . '\'
  and StartDateTime >= ' . gmdate('Y-m-d\\TH:i:s\\Z', $startDate->getTimestamp()) . '
  and StartDateTime <  ' . gmdate('Y-m-d\\TH:i:s\\Z', $endDate->getTimestamp()) . '
order by StartDateTime limit 10000';
        $response = $mySforceConnection->query($query);
        header("Cache-Control: no-cache");
        header('Content-type: text/plain; charset=utf-8');
        //header('Content-Disposition: attachment; filename="' . $calGuid . '.ics"');
        $tzoffset = get_timezone_offset('UTC', $users->records[0]->TimeZoneSidKey);
        $tzoffset = (int) ($tzoffset / 3600) * 100 + (int) ($tzoffset / 60) % 60;
        echo "BEGIN:VCALENDAR\r\n", "PRODID:My Cal\r\n", "VERSION:2.0\r\n", "METHOD:PUBLISH\r\n", "CALSCALE:GREGORIAN\r\n", "BEGIN:VTIMEZONE\r\n", "TZID:", $users->records[0]->TimeZoneSidKey, "\r\n", "BEGIN:STANDARD\r\n", "DTSTART:19700101T000000Z\r\n", "TZOFFSETFROM:", sprintf('%1$+05d', $tzoffset), "\r\n", "TZOFFSETTO:", sprintf('%1$+05d', $tzoffset), "\r\n", "END:STANDARD\r\n", "END:VTIMEZONE\r\n", "X-WR-CALNAME:", escapeText($users->records[0]->Name), "'s calendar\r\n", "X-WR-CALDESC:", escapeText($users->records[0]->Name), "'s calendar\r\n", "X-WR-RELCALID:", $calGuid, "\r\n", "X-WR-TIMEZONE:Asia/Tokyo\r\n";
        foreach ($response->records as $record) {
            $dateFmt = 'Ymd\\THis\\Z';
            $timeAdd = 0;
            if ($record->IsAllDayEvent) {
                $dateFmt = 'Ymd';
                $timeAdd = 3600 * 24;
            }
            echo "BEGIN:VEVENT\r\n", "UID:mycal/", $calGuid, "/", $record->Id, "\r\n", !$record->IsAllDayEvent ? "DTSTAMP:" . gmdate('Ymd\\THis\\Z', strtotime($record->StartDateTime)) . "\r\n" : '', "DTSTART:", gmdate($dateFmt, strtotime($record->StartDateTime)), "\r\n", "DTEND:", gmdate($dateFmt, strtotime($record->EndDateTime) + $timeAdd), "\r\n", "SUMMARY:", escapeText($record->Subject), "\r\n", "DESCRIPTION:", $baseUrl, "/", $record->Id, $showDetail && isset($record->Description) ? '\\n\\n' . escapeText($record->Description) : '', "\r\n", "LOCATION:", isset($record->Location) ? escapeText($record->Location) : '', "\r\n", "END:VEVENT\r\n";
        }
        echo "END:VCALENDAR\r\n";
    } catch (Exception $e) {
        echo $e;
        exit;
    }
}
コード例 #10
0
ファイル: read_event.php プロジェクト: eguicciardi/ada
     * We are inside a tester
     */
    $tester = $sess_selected_tester;
}
/*
 * Find the appointment
 */
$msg_ha = MultiPort::getUserAppointment($userObj, $msg_id);
if (AMA_DataHandler::isError($msg_ha)) {
    $errObj = new ADA_Error($msg_ha, translateFN('Errore durante la lettura di un evento'), NULL, NULL, NULL, 'comunica/list_events.php?status=' . urlencode(translateFN('Errore durante la lettura')));
}
/**
 * Conversione Time Zone
 */
$tester_TimeZone = MultiPort::getTesterTimeZone($tester);
$offset = get_timezone_offset($tester_TimeZone, SERVER_TIMEZONE);
$date_time = $msg_ha['data_ora'];
$date_time_zone = $date_time + $offset;
$zone = translateFN("Time zone:") . " " . $tester_TimeZone;
$Data_messaggio = AMA_DataHandler::ts_to_date($date_time_zone, "%d/%m/%Y - %H:%M:%S") . " " . $zone;
//$Data_messaggio = AMA_DataHandler::ts_to_date($msg_ha['data_ora'], "%d/%m/%Y - %H:%M:%S");
/*
 * Check if the subject has an internal identifier and remove it
 */
$oggetto = ADAEventProposal::removeEventToken($msg_ha['titolo']);
$mittente = $msg_ha['mittente'];
$destinatario = str_replace(",", ", ", $msg_ha['destinatari']);
// $destinatario = $msg_ha['destinatari'];
$dest_encode = urlencode($mittente);
if (isset($message_text) && strlen($message_text) > 0) {
    $testo = urlencode(trim($message_text));
コード例 #11
0
 /**
  * Checks if an event can be proposed in the given date and time
  *
  * @param string $date
  * @param string $time
  * @return TRUE on success, a ADA error code on failure
  */
 public static function canProposeThisDateTime(ADALoggableUser $userObj, $date, $time, $tester = NULL)
 {
     $date = DataValidator::validate_date_format($date);
     if ($date === FALSE) {
         return ADA_EVENT_PROPOSAL_ERROR_DATE_FORMAT;
     } else {
         $current_timestamp = time();
         /**
          * @var timezone management
          */
         $offset = 0;
         if ($tester === NULL) {
             $tester_TimeZone = SERVER_TIMEZONE;
         } else {
             $tester_TimeZone = MultiPort::getTesterTimeZone($tester);
             $offset = get_timezone_offset($tester_TimeZone, SERVER_TIMEZONE);
         }
         $timestamp_time_zone = sumDateTimeFN(array($date, "{$time}:00"));
         $timestamp = $timestamp_time_zone - $offset;
         if ($current_timestamp >= $timestamp) {
             return ADA_EVENT_PROPOSAL_ERROR_DATE_IN_THE_PAST;
         }
         if (MultiPort::hasThisUserAnAppointmentInThisDate($userObj, $timestamp)) {
             return ADA_EVENT_PROPOSAL_ERROR_DATE_IN_USE;
         }
     }
     return TRUE;
 }
コード例 #12
0
ファイル: statslib_test.php プロジェクト: Burick/moodle
    /**
     * Test the temporary table creation and deletion.
     *
     * @depends test_statslib_temp_table_create_and_drop
     */
    public function test_statslib_temp_table_fill() {
        global $CFG, $DB;

        $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test09.xml");

        $this->prepare_db($dataset[0], array('log'));

        $start = self::DAY - get_timezone_offset($CFG->timezone);
        $end   = $start + (24 * 3600);

        stats_temp_table_create();
        stats_temp_table_fill($start, $end);

        $this->assertEquals(1, $DB->count_records('temp_log1'));
        $this->assertEquals(1, $DB->count_records('temp_log2'));

        stats_temp_table_drop();
    }
コード例 #13
0
ファイル: ModifyEvent.php プロジェクト: kisorbiswal/Creamy
}
error_log("Modifying event. Data: " . var_export($_POST, true));
$lh = \creamy\LanguageHandler::getInstance();
$user = \creamy\CreamyUser::currentUser();
// check required fields
$validated = 1;
if (!isset($_POST["event_id"])) {
    // do we have a title?
    $validated = 0;
}
if ($validated == 1) {
    $db = new \creamy\DbHandler();
    // retrieve data for the event.
    $eventid = $_POST["event_id"];
    // calculate proper start and end date, including timezone offset
    $offset = get_timezone_offset($db->getTimezoneSetting(), "UTC");
    $startDate = null;
    $endDate = null;
    $allDay = null;
    if (isset($_POST["start_date"])) {
        $startDate = intval($_POST["start_date"]) / 1000 + intval($offset);
    }
    if (isset($_POST["end_date"])) {
        $endDate = intval($_POST["end_date"] / 1000) + intval($offset);
    }
    if (isset($_POST["all_day"])) {
        $allDay = filter_var($_POST["all_day"], FILTER_VALIDATE_BOOLEAN);
    }
    // modify event
    $result = $db->modifyEvent($user->getUserId(), $eventid, $startDate, $endDate, $allDay);
    // return result
コード例 #14
0
 private static function display_messages_as_form($data_Ar = array(), $message_type = ADA_MSG_SIMPLE, $testers_dataAr = array())
 {
     $common_dh = $GLOBALS['common_dh'];
     $javascript_ok = check_javascriptFN($_SERVER['HTTP_USER_AGENT']);
     $appointments_Ar = array();
     if ($message_type == ADA_MSG_SIMPLE) {
         $list_module = 'list_messages.php';
         $read_module = 'read_message.php';
         $del_img = CDOMElement::create('img', 'src:img/delete.png, name:del_icon');
         $del_img->setAttribute('alt', translateFN('Rimuovi il messaggio'));
         $del_text = translateFN('Cancella');
     } else {
         $list_module = 'list_events.php';
         $read_module = 'read_event.php';
         $del_text = '';
     }
     $order_by_author_link = CDOMElement::create('a', "href:{$list_module}?sort_field=id_mittente");
     $order_by_author_link->addChild(new CText(translateFN('Autore')));
     $order_by_time_link = CDOMElement::create('a', "href:{$list_module}?sort_field=data_ora");
     $order_by_time_link->addChild(new CText(translateFN('Data ed ora')));
     $order_by_subject_link = CDOMElement::create('a', "href:{$list_module}?sort_field=titolo");
     $order_by_subject_link->addChild(new CText(translateFN('Oggetto')));
     $order_by_priority_link = CDOMElement::create('a', "href:{$list_module}?sort_field=priorita");
     $order_by_priority_link->addChild(new CText(translateFN('Priorit&agrave;')));
     $thead_data = array($order_by_author_link, $order_by_time_link, $order_by_subject_link, $order_by_priority_link, $del_text, translateFN('Letto'), '');
     foreach ($data_Ar as $tester => $appointment_data_Ar) {
         //$udh = UserDataHandler::instance(self::getDSN($tester));
         //$tester_info_Ar = $common_dh->get_tester_info_from_pointer($tester);
         $tester_id = $testers_dataAr[$tester];
         //      if (AMA_Common_DataHandler::isError($tester_info_Ar)) {
         //        /*
         //         * Return a ADA_Error with delayed error handling.
         //         */
         //        return new ADA_Error($tester_info_Ar,translateFN('Errore in ottenimento informazioni tester'),
         //                              NULL,NULL,NULL,NULL,TRUE);
         //      }
         $tester_TimeZone = MultiPort::getTesterTimeZone($tester);
         $offset = get_timezone_offset($tester_TimeZone, SERVER_TIMEZONE);
         foreach ($appointment_data_Ar as $appointment_id => $appointment_Ar) {
             // trasform message content into variable names
             $sender_id = $appointment_Ar[0];
             $date_time = $appointment_Ar[1];
             //$subject        = $appointment_Ar[2];
             /*
              * Check if the subject has an internal identifier and remove it.
              */
             //$subject        = preg_replace('/[0-9]+#/','',$appointment_Ar[2],1);
             $subject = ADAEventProposal::removeEventToken($appointment_Ar[2]);
             $priority = $appointment_Ar[3];
             $read_timestamp = $appointment_Ar[4];
             $date_time_zone = $date_time + $offset;
             $zone = translateFN("Time zone:") . " " . $tester_TimeZone;
             $data_msg = AMA_DataHandler::ts_to_date($date_time_zone, "%d/%m/%Y - %H:%M:%S") . " " . $zone;
             //        $data_msg        = AMA_DataHandler::ts_to_date($date_time, "%d/%m/%Y - %H:%M:%S");
             // transform sender's id into sender's name
             //        $res_ar = $udh->find_users_list(array("username"), "id_utente=$sender_id");
             //        if (AMA_DataHandler::isError($res_ar)) {
             //          $sender_username = '';
             //        }
             //        else {
             //          $sender_username = $res_ar[0][1];
             //        }
             $sender_username = $appointment_Ar[6];
             //$msg_id = $tester_info_Ar[0].'_'.$appointment_id;
             $msg_id = $tester_id . '_' . $appointment_id;
             $url = HTTP_ROOT_DIR . '/comunica/' . $read_module . '?msg_id=' . $msg_id;
             $subject_link = CDOMElement::create('a', "href:{$url}");
             $subject_link->addChild(new CText($subject));
             /*
              * If this is a list of simple messages, then deleting is allowed.
              * Otherwise it is disabled.
              */
             if ($message_type == ADA_MSG_SIMPLE) {
                 $delete = CDOMElement::create('checkbox', "name:form[del][{$msg_id}],value:{$msg_id}");
                 $action_link = CDOMElement::create('a', "href:{$list_module}?del_msg_id={$msg_id}");
                 $action_link->addChild($del_img);
             } else {
                 $delete = '';
                 $delete_link = '';
                 // PROVA, POI RIMETTERE A POSTO
                 $userObj = $_SESSION['sess_userObj'];
                 /*
                           if($userObj instanceof ADAPractitioner) {
                  $event_token = ADAEventProposal::extractEventToken($appointment_Ar[2]);
                  $href = HTTP_ROOT_DIR . '/tutor/eguidance_tutor_form.php?event_token=' . $event_token;
                  $action_link = CDOMElement::create('a', "href:$href");
                  $action_link->addChild(new CText(translateFN('View eguidance session data')));
                           }
                 *
                 */
             }
             $read = CDOMElement::create('checkbox', "name:form[read][{$msg_id}],value:{$msg_id}");
             if ($read_timestamp != 0) {
                 $read->setAttribute('checked', 'checked');
             }
             if (!isset($action_link)) {
                 $action_link = null;
             }
             $appointments_Ar[] = array($sender_username, $data_msg, $subject_link, $priority, $delete, $read, $action_link);
         }
     }
     if (count($appointments_Ar) > 0) {
         $table = BaseHtmlLib::tableElement('', $thead_data, $appointments_Ar);
         if (!isset($module)) {
             $module = null;
         }
         $form = CDOMElement::create('form', "name:form, method:post, action:{$module}");
         $form->addChild($table);
         $div = CDOMElement::create('div', 'id:buttons');
         $submit = CDOMElement::create('submit', 'name:btn_commit value:' . translateFN('Salva'));
         $reset = CDOMElement::create('reset', 'name:btn_reset value:' . translateFN('Ripristina'));
         $div->addChild($submit);
         $div->addChild($reset);
         $form->addChild($div);
         return $form;
     } else {
         if ($message_type == ADA_MSG_SIMPLE) {
             return new CText(translateFN('Non ci sono nuovi messaggi'));
         }
         return new CText(translateFN('Non ci sono nuovi appuntamenti'));
     }
 }