/**
  * This functions saves in cache the destination boxes values
  *
  * @param array $aryboxes The new destboxes array
  * @param array $deleted An array of booleans with keys similar to the destboxes array
  * If a given destination box has a true entry here, it will be removed in the cache
  * @return array We return what we couldn't find in cache so the caller can evaluate if he needs to refresh his info
  *
  * Note that this function can be mistaken by the save_destboxes function.
  * Different things completely. This one takes an array of destboxes. The keys to this array
  * are the destboxes names. Inside each array, there are uid => name pairs. Note the absence
  * of an email field. The incoming aryboxes have NO email field whatsoever.
  * What we do here, is try and find the corresponding email fields either in cache or directly
  * in our mass query cache and set that field correctly to save it in cache
  *
  * @internal This function is redundant, inneficient and dead slow. Not to say complex and unreadable
  * Please change this please please please.
  * Previous disclaimer said, it works now, and will release this way.
  */
 function set_destboxes($aryboxes, $deleted = '')
 {
     //print_r($aryboxes);
     //print "<br />SAVed DESTBOXES<br />";
     //We get our own destboxes from the cache
     $saveddestboxes = $this->get_destboxes();
     $GLOBALS['debug_timer_start'] = perfgetmicrotime();
     //print_r($saveddestboxes);
     $found = false;
     //We iterate into each box
     while (list($ak, $li) = each($aryboxes)) {
         //print $ak." ".$li."<br />";
         //print_r($li);
         //print "<br />";
         //We make shure this box has an array in it
         if ($aryboxes[$ak]) {
             //We iterate into the incoming box to search
             //for its values in the cache
             while (list($numary, $ary) = each($aryboxes[$ak])) {
                 //print "<br /> Iterating aryboxes $numary";
                 //print_r($ary);
                 list($id, $name) = each($ary);
                 //Look for this record in the cached destboxes
                 if (is_array($saveddestboxes[$ak])) {
                     //Well, we found that we have this destboxed cached so
                     //now we will iterate through that
                     while (list($numarysave, $arysave) = each($saveddestboxes[$ak])) {
                         //We will try and get each addressbook key
                         //out of the cached destbox
                         list($sid, $sname) = each($arysave);
                         //print "<br /> Iterating destboxes $id -> $name / $sid $sname";
                         //So we can compare it and set the email field in it
                         if ($id == $sid) {
                             //print "<br /> found $id in $ak";
                             //print "<br /> seting mail to $arysave[email]";
                             $ary['email'] = $arysave['email'];
                             $aryboxes[$ak][$numary] = $ary;
                             $found = true;
                         }
                     }
                     reset($saveddestboxes[$ak]);
                 }
                 //couldnt find it in saved destboxes, lookfor ir in result
                 //This redundant POSH makes me angry....
                 //Now we look into our names cache...im not shure why, if i
                 //try and evade this search when i find it in the cache,
                 //it all goes borken
                 //We iterate into the query cache
                 if (strpos($id, 'id_') !== false) {
                     $categoryobject = CreateObject('phpgwapi.categories');
                     $categoryobject->app_name = 'addressbook';
                     $cat_id = substr($id, 3);
                     //$cat_name = $categoryobject->id2name($cat_id);
                     //$cat_email = "cat:$cat_id:$cat_name@grupogonher.com";
                     $cat_email = "id_{$cat_id}@lists.com";
                     $ary['email'] = $cat_email;
                     $aryboxes[$ak][$numary] = $ary;
                     $retboxes[$ak][$id]['email'] = $ary['email'];
                     $retboxes[$ak][$id]['name'] = $name;
                 } else {
                     while (list($num, $record) = each($this->result)) {
                         //print "<br> Iterating results $id   ---> $name <br>$record[id]---> $record[email]";
                         //Found what we are looking for
                         if ($id == $record["contact_id"]) {
                             //Set the mail record to what it should be
                             //print "<br> seting mail to $record[email] <br>";
                             $ary['email'] = $record["email"] ? $record["email"] : $record["home_email"];
                             $aryboxes[$ak][$numary] = $ary;
                             $retboxes[$ak][$id]['email'] = $ary['email'];
                             $retboxes[$ak][$id]['name'] = $name;
                         }
                     }
                     reset($this->result);
                 }
                 $found = false;
             }
         } elseif (!$deleted[$ak]) {
             //print "<br />Saving $ak from destination data $deleted[$ak]<br />";
             //print_r($deleted);
             //Delete the destboxes that need deletion
             $aryboxes[$ak] = $saveddestboxes[$ak];
         }
     }
     //print "<br />modified<br />";
     //print_r($aryboxes);
     reset($aryboxes);
     //Save the resulting destboxes
     $GLOBALS['debug_timer_stop'] = perfgetmicrotime();
     //print("<br />Set destboxes in ". ($GLOBALS['debug_timer_stop'] - $GLOBALS['debug_timer_start']) . " seconds.");
     $this->save_destboxes($aryboxes);
     //We return what we couldnt find in cache so the caller can evaluate
     //if he needs to refresh his info...
     return $retboxes;
 }
}
/* debugging settings */
define('DEBUG_APP', False);
define('DEBUG_API', False);
define('DEBUG_DATATYPES', True);
define('DEBUG_LEVEL', 3);
define('DEBUG_OUTPUT', 2);
/* 1 = screen,  2 = DB. For both use 3. */
define('DEBUG_TIMER', False);
function perfgetmicrotime()
{
    list($usec, $sec) = explode(' ', microtime());
    return (double) $usec + (double) $sec;
}
if (DEBUG_TIMER) {
    $GLOBALS['debug_timer_start'] = perfgetmicrotime();
}
/**************************************************************************\
	* Do not edit these lines                                                  *
	\**************************************************************************/
define('PHPGW_API_INC', PHPGW_INCLUDE_ROOT . '/phpgwapi/inc');
include PHPGW_SERVER_ROOT . '/phpgwapi/setup/setup.inc.php';
$GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] = $setup_info['phpgwapi']['version'];
$GLOBALS['phpgw_info']['server']['versions']['current_header'] = $setup_info['phpgwapi']['versions']['current_header'];
unset($setup_info);
$GLOBALS['phpgw_info']['server']['versions']['header'] = '1.27';
/* This is a fix for NT */
if (!isset($GLOBALS['phpgw_info']['flags']['noapi']) || !$GLOBALS['phpgw_info']['flags']['noapi'] == True) {
    include PHPGW_API_INC . '/functions.inc.php';
    include PHPGW_API_INC . '/xml_functions.inc.php';
    include PHPGW_API_INC . '/soap_functions.inc.php';
Example #3
0
    $GLOBALS['phpgw']->redirect_link('/home.php');
}
if ($api_requested) {
    $app = 'phpgwapi';
}
$GLOBALS[$class] = CreateObject("{$app}.{$class}");
if (!$invalid_data && is_object($GLOBALS[$class]) && isset($GLOBALS[$class]->public_functions) && is_array($GLOBALS[$class]->public_functions) && isset($GLOBALS[$class]->public_functions[$method]) && $GLOBALS[$class]->public_functions[$method]) {
    if (phpgw::get_var('X-Requested-With', 'string', 'SERVER') == 'XMLHttpRequest' || phpgw::get_var('phpgw_return_as', 'string', 'GET') == 'json') {
        // comply with RFC 4627
        header('Content-Type: application/json');
        $return_data = $GLOBALS[$class]->{$method}();
        echo json_encode($return_data);
        $GLOBALS['phpgw_info']['flags']['nofooter'] = true;
        //If debug info is not triggered elsewhere.
        if (isset($GLOBALS['phpgw_info']['user']['apps']['admin']) && DEBUG_TIMER && !phpgwapi_cache::session_get($app, 'id_debug')) {
            $debug_timer_stop = perfgetmicrotime();
            //BTW: wil not destroy the json output - click on the 'Debug-link' to view message
            _debug_array(lang('page prepared in %1 seconds.', $debug_timer_stop - $GLOBALS['debug_timer_start']));
        }
        $GLOBALS['phpgw']->common->phpgw_exit();
    } else {
        if (phpgw::get_var('phpgw_return_as', 'string', 'GET') == 'noframes') {
            $GLOBALS['phpgw_info']['flags']['noframework'] = true;
            $GLOBALS['phpgw_info']['flags']['headonly'] = true;
        }
        $GLOBALS[$class]->{$method}();
    }
    unset($app);
    unset($class);
    unset($method);
    unset($invalid_data);