Example #1
0
function printout_mysqlerror()
{
    if (mysql_error()) {
        printout(mysql_error());
    }
}
        while (list($key, $table) = @each($tables)) {
            $i++;
            if ($i == $tbls) {
                $term = '';
            }
            parse_vars($table, $term);
            $dlstring .= printout('sqlbody');
            /* $i++; */
        }
        $dlstring .= printout('sqlfooter');
    } elseif ($table) {
        $term = ';';
        parse_vars($table, $term);
        $dlstring .= printout('sqlheader');
        $dlstring .= printout('sqlbody');
        $dlstring .= printout('sqlfooter');
    }
    if ($download) {
        download_handler($dlstring);
    }
} else {
    $GLOBALS['phpgw_setup']->html->show_header();
    $setup_tpl->set_var('action_url', 'sqltoarray.php');
    $setup_tpl->set_var('lang_submit', 'Show selected');
    $setup_tpl->set_var('lang_showall', 'Show all');
    $setup_tpl->set_var('title', 'SQL to schema_proc array util');
    $setup_tpl->set_var('lang_applist', 'Applications');
    $setup_tpl->set_var('select_to_download_file', lang('Select to download file'));
    $setup_tpl->pfp('out', 'appheader');
    $d = dir(PHPGW_SERVER_ROOT);
    while ($entry = $d->read()) {
Example #3
0
 /**
  * Creates the items added by createCalendarItems_addItem
  *
  * @return  array  Response message(s)
  */
 public function createCalendarItems()
 {
     if (!$this->have_started_createItem) {
         $this->createCalenderItems_shutdown();
         throw new Exception('No items added.');
     }
     if (count($this->CreateItem->Items->CalendarItem) == 0) {
         $this->createCalenderItems_shutdown();
         throw new Exception('No items added.');
     }
     $result = $this->client->CreateItem($this->CreateItem);
     // < $this->client holds SOAP-client object
     if (count($this->CreateItem->Items->CalendarItem) > 1) {
         $ids = array();
         foreach ($result->ResponseMessages->CreateItemResponseMessage as $i => $response) {
             if ($response->ResponseClass == 'Success') {
                 // Returning the id/changekey for each item
                 $ids[$i] = array('Id' => $response->Items->CalendarItem->ItemId->Id, 'ChangeKey' => $response->Items->CalendarItem->ItemId->ChangeKey);
             } else {
                 // If there is no success, return null
                 printout('Item ' . $i . ' failed creation: ' . print_r($response, true));
                 $ids[$i] = array('Id' => null, 'ResponseMessage' => $response);
             }
         }
         $this->createCalenderItems_shutdown();
         return $ids;
     }
     if ($result->ResponseMessages->CreateItemResponseMessage->ResponseClass == 'Success') {
         // Returning the id/changekey in an array with only one item
         $this->createCalenderItems_shutdown();
         return array(0 => array('Id' => $result->ResponseMessages->CreateItemResponseMessage->Items->CalendarItem->ItemId->Id, 'ChangeKey' => $result->ResponseMessages->CreateItemResponseMessage->Items->CalendarItem->ItemId->ChangeKey));
     } else {
         // Return null
         $this->createCalenderItems_shutdown();
         return array(0 => array('Id' => null, 'ResponseMessage' => $result->ResponseMessages->CreateItemResponseMessage));
     }
 }
Example #4
0
function exchangesync_syncItems($cal, $user, $user_id, $entries_sync)
{
    global $alert_admin, $alerts;
    global $systemurl;
    global $entryObj;
    global $created_items, $deleted_items;
    // "Returns"
    global $area;
    // Build where statement for query and add items that needs to be created
    $entries_new = array();
    $delete_where = array();
    foreach ($entries_sync as $entry_id => $entry) {
        // Only create new if the user is still assigned to entry
        if (isset($entry['user_assigned'][$user_id])) {
            //$entry = getEntry($entry['entry_id']); // Need more information
            templateAssignEntry('entryObj', $entry);
            $rooms = $entryObj->room . ' (' . $area[$entry['area_id']] . ')';
            // Add the entry to list of items
            $i = $cal->createCalendarItems_addItem(utf8_encode($entryObj->entry_name), exchangesync_getEntryCalendarDescription($systemurl, $entryObj), date('c', $entryObj->time_start), date('c', $entryObj->time_end), array('ReminderIsSet' => false, 'Location' => utf8_encode($rooms)), $user['user_ews_sync_email']);
            $entries_new[$i] = $entry['entry_id'];
        }
        // Delete this entry for this user
        $delete_where[] = '(`entry_id` = \'' . $entry_id . '\' && `user_id` = \'' . $user_id . '\')';
    }
    // Delete in Exchange
    $Q_sync = mysql_query("select * from `entry_exchangesync`\n\t\tWHERE " . implode(' || ', $delete_where));
    $deleted_items = array();
    while ($R_sync = mysql_fetch_assoc($Q_sync)) {
        try {
            $deleted_item = $cal->deleteItem($R_sync['exchange_id']);
            $deleted_items[$R_sync['entry_id']] = $deleted_item;
            printout($R_sync['entry_id'] . ' deleted');
        } catch (Exception $e) {
            printout('Exception - deleteItem - ' . $R_sync['entry_id'] . ': ' . $e->getMessage());
            $alert_admin = true;
            $alerts[] = 'deleteItem exception';
        }
    }
    // Delete all the exchangesync data
    $Q_sync = mysql_query("delete from `entry_exchangesync`\n\t\tWHERE " . implode(' || ', $delete_where));
    printout_mysqlerror();
    // Create the new items
    $created_items = array();
    try {
        if (count($entries_new)) {
            $created_items = $cal->createCalendarItems();
        } else {
            printout('No calendar items to be created');
        }
    } catch (Exception $e) {
        printout('Exception - createCalendarItems: ' . $e->getMessage() . '<br />');
        $alert_admin = true;
        $alerts[] = 'createCalendarItems exception: ' . $e->getMessage();
    }
    foreach ($created_items as $i => $ids) {
        if (!is_null($ids['Id'])) {
            $entry = $entries_sync[$entries_new[$i]];
            printout($entries_new[$i] . ' created.');
            // Inserting in sync
            mysql_query("INSERT INTO `entry_exchangesync` (\n\t\t\t\t`entry_id` ,\n\t\t\t\t`exchange_id` ,\n\t\t\t\t`exchange_changekey`,\n\t\t\t\t`user_id`,\n\t\t\t\t`entry_rev`,\n\t\t\t\t`sync_from`,\n\t\t\t\t`sync_to`\n\t\t\t)\n\t\t\tVALUES (\n\t\t\t\t'" . $entry['entry_id'] . "' , \n\t\t\t\t'" . $ids['Id'] . "', \n\t\t\t\t'" . $ids['ChangeKey'] . "',\n\t\t\t\t'" . $user_id . "',\n\t\t\t\t'" . $entry['rev_num'] . "',\n\t\t\t\t'" . $entry['time_start'] . "',\n\t\t\t\t'" . $entry['time_end'] . "'\n\t\t\t);");
            printout_mysqlerror();
        } else {
            if ($ids['ResponseMessage']->ResponseCode == 'ErrorCreateItemAccessDenied') {
                // Alert admin, alert user and disable sync
                emailSend($user_id, 'Ikke tilgang til kalender', exchangesync_getUsermsgAccessDenied($systemurl));
                mysql_query("UPDATE `users` SET `user_ews_sync` = '0' WHERE `user_id` =" . $user_id);
                printout($entries_new[$i] . ' not created. User ' . $user_id . ' has access denied error when creating items. Has disabled the sync of this user. Message from Exchange: ' . $ids['ResponseMessage']->MessageText);
                $alert_admin = true;
                $alerts[] = $entries_new[$i] . ' not created. User ' . $user_id . ' has access denied error when creating items. Has disabled the sync of this user. Message from Exchange: ' . $ids['ResponseMessage']->MessageText;
            } else {
                // Unknown error, alert admin
                printout($entries_new[$i] . ' not created: ' . print_r($ids['ResponseMessage'], true));
                $alert_admin = true;
                $alerts[] = $entries_new[$i] . ' not created. Message from Exchange: ' . $ids['ResponseMessage']->MessageText;
            }
        }
    }
}
    if (is_null($calendaritems[$user_id])) {
        printout('getCalendarItems failed: ' . $cal->getError());
    } else {
        // Going through existing elements
        foreach ($calendaritems[$user_id] as $item) {
            if (!isset($item->Subject)) {
                $item->Subject = '';
            }
            $cal_ids[$item->ItemId->Id] = $item->ItemId->ChangeKey;
            printout('Existing: ' . $item->Start . '   ' . $item->End . '   ' . $item->Subject);
        }
    }
    $item = array('id' => '1337', 'title' => 'Test', 'text' => 'Tekst');
    $items_new[$user_id] = array();
    $i = $cal->createCalendarItems_addItem($item['title'], $item['text'], date('c'), date('c', time() + 60 * 60), array('ReminderIsSet' => false, 'Location' => 'Interwebs'), $user_email);
    $items_new[$user_id][$i] = $item['id'];
    /* ## CREATE ITEMS ## */
    try {
        $created_items = $cal->createCalendarItems();
    } catch (Exception $e) {
        printout('Exception - createCalendarItems: ' . $e->getMessage() . '<br />');
        $created_items = array();
    }
    foreach ($created_items as $i => $ids) {
        if (!is_null($ids['Id'])) {
            printout($items_new[$user_id][$i] . ' created.');
        } else {
            printout($items_new[$user_id][$i] . ' not created: ' . print_r($ids['ResponseMessage'], true));
        }
    }
}
Example #6
0
        // Inserting in sync
        mysql_query("INSERT INTO `sync` (\n\t\t\t`item_id` ,\n\t\t\t`e_id` ,\n\t\t\t`e_changekey`,\n\t\t\t`user`,\n\t\t\t`time`\n\t\t)\n\t\tVALUES (\n\t\t\t'" . $items_new[$i] . "' , \n\t\t\t'" . $ids['Id'] . "', \n\t\t\t'" . $ids['ChangeKey'] . "',\n\t\t\t'" . $login['username'] . "',\n\t\t\t'" . time() . "'\n\t\t);");
        echo mysql_error();
    } else {
        printout($items_new[$user_id][$i] . ' not created: ' . print_r($ids['ResponseMessage'], true));
    }
}
/* ## DELETE ITEMS ## */
$deleted_items = array();
foreach ($items_delete as $item_id => $item) {
    try {
        $deleted_item = $cal->deleteItem($sync[$item['id']]['e_id']);
        $deleted_items[$item['id']] = $deleted_item;
        printout($item['id'] . ' deleted');
    } catch (Exception $e) {
        printout('Exception - deleteItem - ' . $item['id'] . ': ' . $e->getMessage());
    }
}
/*
foreach($deleted_items as $i => $ids)
{
	if(!is_null($ids)) // Null = unsuccessful
	{
		printout($items_new[$i].' synced (created).');
		mysql_query("INSERT INTO `sync` (
			`item_id` ,
			`e_id` ,
			`e_changekey`,
			`user`,
			`time`
		)