function fetchPage()
 {
     require_once PATH_CORE . '/classes/resources.class.php';
     $resObj = new resources($this->db);
     $code .= $resObj->buildLinksColumn();
     return $code;
 }
Exemple #2
0
 static function transform1($params)
 {
     $url = $params['image'];
     $data = $params['data'];
     $info = image::image_info($url);
     $path = $info['path'];
     if (!io::file_exists($path)) {
         throw new \Exception(resources::message('FILE_NOT_EXISTS', $path));
     }
     if (meta::exists($info['id'])) {
         $meta = meta::get($info['id']);
         $spath = util::apath($meta['orig']);
         $data = isset($meta['data']) ? image::combine_transform($meta['data'], $data) : $data;
     } else {
         $spath = $path;
     }
     $id = util::id();
     $name = $id . '.' . $info['ext'];
     $dpath = DRAFT_CONTENT_DIR . '/' . $name;
     image::transform_image($spath, $dpath, $data);
     meta::put($id, array('orig' => util::rpath($spath), 'oid' => $info['id'], 'path' => util::rpath($dpath), 'name' => $name, 'data' => $data, 'image' => true));
     return array('status' => 0, 'url' => DRAFT_CONTENT_URL . '/' . $name);
 }
 private function processForm()
 {
     $mail = services::getService('mail');
     $params = services::getService('pageParams');
     // form procession
     $res = new resources();
     if ($params->getParam('submit')) {
         $res->get($params->getParam('id'));
         // no item
         if ($res->type == 0) {
             $res->addBorrow($this->user->id, $params->getParam('comments'));
             $this->addMsg('msg_added_request');
             $owner = new user();
             $owner->get($res->user_id);
             $mail->send('nogood_order', $owner, $res, $this->user, $params->getParam('comments'));
         }
         // beeing given
         if ($res->type == 1) {
             $res->addGiven($this->user->id, $params->getParam('comments'));
             $this->addMsg('msg_added_given');
             $owner = new user();
             $owner->get($res->user_id);
             $mail->send('give_order', $owner, $res, $this->user, $params->getParam('comments'));
         }
         // borrow
         if ($res->type == 2) {
             $res->addBorrow($this->user->id, $params->getParam('comments'));
             $this->addMsg('msg_added_borrow');
             $owner = new user();
             $owner->get($res->user_id);
             $mail->send('borrow_order', $owner, $res, $this->user, $params->getParam('comments'));
         }
     }
 }
// Add widgets
$q = $db->query("SELECT * FROM Widgets WHERE title='evan' OR title='kfintro'");
if ($db->countQ($q) == 0) {
    $db->insert("Widgets", "title,wrap,html,smartsize,width,height,style,type,isAd", "'kfintro','<div id=\"featurePanel\" class=\"clearfix\">\r\n<div class=\"panelBar clearfix\">\r\n<h2>Featured Video</h2>\r\n<div class=\"bar_link\">About our funder, the <a href=\"http://knightfoundation.org\" target=\"_blank\">Knight Foundation</a></div>\r\n</div><div class=\"subtitle\"><a href=\"http://blog.newscloud.com/2008/12/knight_announce.html\" target=\"_blank\">Learn more</a> about NewsCloud\\'s open source grant</div><!--end \"panelBar\"-->\r\n<div style=\"background-color:#FFFFFF;text-align:center;\">{widget}</div>\r\n</div><!--end \"featurePanel\"-->\r\n\r\n','<object width=\"400\" height=\"230\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=4358677&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=4358677&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"400\" height=\"230\"></embed></object>','0','480','240','','script','0'");
    $kfId = $db->getId();
    $db->insert("Widgets", "title,wrap,html,smartsize,width,height,style,type,isAd", "'evan','<div id=\"featurePanel\" class=\"clearfix\">\r\n<div class=\"panelBar clearfix\">\r\n<h2>Featured Video</h2>\r\n<div class=\"bar_link\">Sometimes Daily Reports on Evan Ratliff\\'s Capture</div>\r\n</div><!--end \"panelBar\"-->\r\n<center>{widget}</center>\r\n</div><!--end \"featurePanel\"-->\r\n\r\n','<embed src=\"http://blip.tv/play/g55igaDBcgI%2Em4v\" type=\"application/x-shockwave-flash\" width=\"480\" height=\"299\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed> ','0','480','310','','script','0'");
    $evanId = $db->getId();
    $db->update("Content", "widgetid={$evanId}", "url='http://www.wired.com/vanish/2009/09/how-evan-ratliff-was-caught/'");
    $db->delete("FeaturedWidgets");
    $db->insert("FeaturedWidgets", "widgetid,locale,position", "{$kfId},'homeFeature',1");
}
// Add folders and Links
$db->delete("Folders", "title='About NewsCloud' OR title='About Facebook'");
$db->delete("FolderLinks", "folderid NOT IN (select folderid from Folders )");
require_once SRC_ROOT . '/core/classes/resources.class.php';
$rObj = new resources($db);
$folder = $rObj->serializeFolder(0, 0, 'About NewsCloud');
$folderid = $rObj->addFolder($folder);
$li = $rObj->serializeLink(0, $folderid, 0, 'NewsCloud Blog', 'http://blog.newscloud.com', 'link', '', '');
$rObj->addLink($li);
$folder2 = $rObj->serializeFolder(0, 0, 'About Facebook');
$folderid2 = $rObj->addFolder($folder2);
$li2 = $rObj->serializeLink(0, $folderid2, 0, 'Facebook', 'http://www.facebook.com', 'link', '', '');
$rObj->addLink($li2);
// Add ads
echo 'Adding sample advertisment(s)...<br />';
$db->delete("AdCode");
$db->insert("AdCode", "site,clientid,format,locale,code,codeType,impRemaining,status", "'smallBanner','0','smallBanner','homeSmallBanner','<html><head>\n\t<script type=\"text/javascript\" src=\"http://partner.googleadservices.com/gampad/google_service.js\">\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GS_googleAddAdSenseService(\"ca-pub-9975156792632579\");\n\t  GS_googleEnableAllServices();\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GA_googleAddSlot(\"ca-pub-9975156792632579\", \"Needle_Small\");\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GA_googleFetchAds();\n\t</script>\n\t</head>\n\t<body>\n\t<script type=\"text/javascript\">\n\t  GA_googleFillSlot(\"Needle_Small\");\n\t</script>\n\t</body>\n\t</html>','iframe','0','active'");
$db->insert("AdCode", "site,clientid,format,locale,code,codeType,impRemaining,status", "'smallBanner','0','smallBanner','anySmallBanner','<html><head>\n\t<script type=\"text/javascript\" src=\"http://partner.googleadservices.com/gampad/google_service.js\">\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GS_googleAddAdSenseService(\"ca-pub-9975156792632579\");\n\t  GS_googleEnableAllServices();\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GA_googleAddSlot(\"ca-pub-9975156792632579\", \"Needle_Small\");\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GA_googleFetchAds();\n\t</script>\n\t</head>\n\t<body>\n\t<script type=\"text/javascript\">\n\t  GA_googleFillSlot(\"Needle_Small\");\n\t</script>\n\t</body>\n\t</html>','iframe','0','active'");
$db->insert("AdCode", "site,clientid,format,locale,code,codeType,impRemaining,status", "'largeBanner','0','largeBanner','anyLargeBanner','<html><head>\n\t<script type=\"text/javascript\" src=\"http://partner.googleadservices.com/gampad/google_service.js\"></script>\n\t<script type=\"text/javascript\">\n\t  GS_googleAddAdSenseService(\"ca-pub-9975156792632579\");\n\t  GS_googleEnableAllServices();\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GA_googleAddSlot(\"ca-pub-9975156792632579\", \"AnyLargeBanner\");\n\t</script>\n\t<script type=\"text/javascript\">\n\t  GA_googleFetchAds();\n\t</script>\n\t</head>\n\t<body>\n\t<script type=\"text/javascript\">\n\t  GA_googleFillSlot(\"AnyLargeBanner\");\n\t</script></body></html>','iframe','0','active'");
$db->insert("AdCode", "site,clientid,format,locale,code,codeType,impRemaining,status", "'skyscraper','0','skyscraper','anySkyscraper','<html><head><script type=\\'text/javascript\\' src=\\'http://partner.googleadservices.com/gampad/google_service.js\\'>\n\t</script>\n\t<script type=\\'text/javascript\\'>\n\t  GS_googleAddAdSenseService(\\'ca-pub-9975156792632579\\');\n\t  GS_googleEnableAllServices();\n\t</script>\n\t<script type=\\'text/javascript\\'>\n\t  GA_googleAddSlot(\\'ca-pub-9975156792632579\\', \\'Needly_Skyscraper\\');\n\t</script>\n\t<script type=\\'text/javascript\\'>\n\t  GA_googleFetchAds();\n\t</script></head><body>\n\t<script type=\\'text/javascript\\'>\n\t  GA_googleFillSlot(\\'Needly_Skyscraper\\');\n\t</script></body></html>','iframe','0','active'");
 /**
  * Mehrsprachigen Monat (langer Name) zurückgeben
  * @param integer nMonth, Monatsnummer 1 - 12
  * @param resources Res, Sprachobjekt
  * @return string Name des gewünschten Monats
  */
 public static function getMonthName($nMonth, resources &$Res)
 {
     // Switchen und Resourcen holen
     switch ($nMonth) {
         case 1:
             $sMonth = $Res->html(582, page::language());
             break;
         case 2:
             $sMonth = $Res->html(583, page::language());
             break;
         case 3:
             $sMonth = $Res->html(584, page::language());
             break;
         case 4:
             $sMonth = $Res->html(585, page::language());
             break;
         case 5:
             $sMonth = $Res->html(586, page::language());
             break;
         case 6:
             $sMonth = $Res->html(587, page::language());
             break;
         case 7:
             $sMonth = $Res->html(588, page::language());
             break;
         case 8:
             $sMonth = $Res->html(589, page::language());
             break;
         case 9:
             $sMonth = $Res->html(590, page::language());
             break;
         case 10:
             $sMonth = $Res->html(591, page::language());
             break;
         case 11:
             $sMonth = $Res->html(592, page::language());
             break;
         case 12:
             $sMonth = $Res->html(593, page::language());
             break;
     }
     // Wochentag zurückgeben
     return $sMonth;
 }
 function runJob($job, $force = false)
 {
     $stopAfterJob = false;
     $startTime = microtime(true);
     $this->log($job->task . ', started ' . date('g:i a \\a\\t D M n, Y', $startTime));
     if (!isset($_GET['test']) && !$force) {
         if ($job->isRunning == 1) {
             $this->db->log('Cron race condition: ' . $job->task . ' last start= ' . $job->lastStart);
             echo 'Warning: Cron Race condition<br />';
             return;
         } else {
             $this->db->update("cronJobs", "isRunning=1,failureNoticeSent=0", "id={$job->id}");
         }
     }
     //echo 'Task: '.$job->task."\n";
     switch ($job->task) {
         default:
             // do nothing
             break;
         case 'updateUserLevels':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateUserLevels();
             break;
         case 'updateSiteChallenges':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateSiteChallenges();
             break;
         case 'updateCachedPointsAndChallenges':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateCachedPointsAndChallenges();
             break;
         case 'calcWeeklyLeaders':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->calcWeeklyLeaders();
             break;
         case 'updateUserLevels':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateUserLevels();
         case 'updateTwitter':
             // post top stories to twitter
             if (USE_TWITTER) {
                 require_once 'twitter.class.php';
                 $twitterObj = new twitter_old($this->db);
                 $twitterObj->postFeaturedStories();
                 $twitterObj->postNextTopStory();
             }
             break;
         case 'microAccountsSync':
             // sync twitter service accounts for micro blog room - done daily
             if (defined('ENABLE_MICRO')) {
                 require_once PATH_FACEBOOK . "/classes/micro.class.php";
                 $mObj = new micro();
                 $mObj->cleanRoom();
                 try {
                     $mObj->resetFriends(false);
                 } catch (Exception $e) {
                     $this->log('Failed running ' . $job->task . ', Error: ' . $e);
                     // reset this cron task manually because of twitter class trown exceptions
                     $execTime = microtime(true) - $startTime;
                     $this->db->update("cronJobs", "nextRun=date_sub(NOW(), INTERVAL (0-{$job->freqMinutes}) MINUTE),lastExecTime={$execTime},lastStart='" . date('Y-m-d H:i:s', $startTime) . "',isRunning=0", "id={$job->id}");
                 }
             }
             break;
         case 'microBlog':
             // post top stories to micro blog room
             if (defined('ENABLE_MICRO')) {
                 require_once PATH_FACEBOOK . "/classes/micro.class.php";
                 $mObj = new micro();
                 try {
                     $mObj->updateRoom();
                 } catch (Exception $e) {
                     $this->log('Failed running ' . $job->task . ', Error: ' . $e);
                     // reset this cron task manually because of twitter class trown exceptions
                     $execTime = microtime(true) - $startTime;
                     $this->db->update("cronJobs", "nextRun=date_sub(NOW(), INTERVAL (0-{$job->freqMinutes}) MINUTE),lastExecTime={$execTime},lastStart='" . date('Y-m-d H:i:s', $startTime) . "',isRunning=0", "id={$job->id}");
                 }
             }
             break;
         case 'updateCache':
             // build cached content for cover page layout
             require_once 'cache.class.php';
             $cacheObj = new cache($this->db);
             $cacheObj->update();
             break;
         case 'syncProperties':
             // sync Cloud properties with NewsCloud services
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $props = $apiObj->syncProperties($this->cloudid);
             require_once 'systemStatus.class.php';
             $ssObj = new systemStatus($this->db);
             $ssObj->setProperties($props['items'][0]);
             break;
         case 'syncAnnouncements':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $resp = $apiObj->syncAnnouncements($this->cloudid);
             if ($resp[result] !== false) {
                 $itemlist = $resp[items];
                 require_once 'systemStatus.class.php';
                 $ssObj = new systemStatus($this->db);
                 $ssObj->resetAnnouncements();
                 if (count($itemlist) > 0) {
                     foreach ($itemlist as $data) {
                         $ssObj->insertState('announcement', html_entity_decode($data['announce']));
                     }
                 }
             }
             break;
         case 'syncNewswire':
             /* deprecated
             			require_once ('apiCloud.class.php');
             			$apiObj=new apiCloud($this->db,$this->apiKey);
             			$resp=$apiObj->syncNewswire($this->cloudid,$this->timeStrToUnixModB($job->lastItemTime));
             			$itemlist=$resp[items];
             			echo 'count: '.count($itemlist).'<br />';
             			if (count($itemlist)>0) {
             				require_once('newswire.class.php');
             				$nwObj=new newswire($this->db);
             				$lastItemTime=date('Y-m-d H:i:s',(time()-(6*30*24*3600))); // set to six months earlier 
             				foreach ($itemlist as $data) {					
             					$wire=$nwObj->serialize($data[title],$data[caption],$data[blogtitle],$data[webpage],$data[date],$data[blogid]);						
             					$id=$nwObj->add($wire);
             					if ($data[date]>$lastItemTime)						
             						$lastItemTime=$data[date];
             					if ($id===false)
             						echo 'skip '.$data[title].'<br />';
             					else						
             						echo 'adding '.$data[title].' id->'.$id.'<br />';
             				}
             				$this->db->update("cronJobs","lastItemTime='$lastItemTime'","id=$job->id");
             			}
             			*/
             break;
         case 'syncLog':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             // request server ask for log
             $resp = $apiObj->requestSyncLog($this->cloudid, URL_HOME, $this->timeStrToUnixModB($job->lastStart));
             // get result of log sync
             $logResult = $resp[items][0][log];
             require_once PATH_CORE . "/classes/log.class.php";
             $logObj = new log($this->db);
             // process results from sync operation
             $result = $logObj->receive($logResult);
             echo $result;
             break;
         case 'syncContent':
             // bring content from NewsCloud for this cloud to the remote site
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $resp = $apiObj->syncContent($this->cloudid, $this->timeStrToUnixModB($job->lastItemTime));
             $itemlist = $resp[items];
             if (count($itemlist) > 0) {
                 require_once 'content.class.php';
                 $cObj = new content($this->db);
                 // to do : set this to actual time
                 $lastItemTime = date('Y-m-d H:i:s', time() - 6 * 30 * 24 * 3600);
                 // set to six months earlier
                 foreach ($itemlist as $data) {
                     echo 'Contentid' . $data[contentid] . '<br />';
                     // to do: before we can do this below, we need to be syncing ncuid when new users register
                     // to do: get userid from ncUid
                     // lookup userid in user table where ncuid=submitbyid
                     // if not found make it 0
                     // to do: if external story, then check for local userid and set here
                     $story = $cObj->serialize($data[contentid], $data[title], $data[description], '', $data[webpage], $data[permalink], $data[submitbyid], $data[submit_member], $data[userid], $data[date], $data[avgrank], 0, $data[imageid]);
                     $id = $cObj->add($story);
                     // update comments table with new contentids
                     $cObj->updateCommentsTable($data[contentid], $id);
                     if ($data[date] > $lastItemTime) {
                         $lastItemTime = $data[date];
                     }
                     echo 'story added' . $id . '<br><br/>';
                 }
                 $this->db->update("cronJobs", "lastItemTime='{$lastItemTime}'", "id={$job->id}");
             }
             break;
         case 'syncComments':
             // bring comments from stories in this cloud from NewsCloud over to remote site
             require_once 'content.class.php';
             $cObj = new content($this->db);
             $idList = $cObj->fetchRecentStoryList(14, 99, true);
             $this->db->log('syncComments - stories to check for.', PATH_SYNCLOGFILE);
             $this->db->log($idList, PATH_SYNCLOGFILE);
             if ($idList != '') {
                 require_once 'comments.class.php';
                 $commentsObj = new comments($this->db);
                 require_once 'apiCloud.class.php';
                 $apiObj = new apiCloud($this->db, $this->apiKey);
                 $result = $apiObj->syncComments($this->cloudid, $idList, $this->timeStrToUnixModB($job->lastItemTime));
                 $itemlist = $result[items];
                 $this->db->log($itemlist, PATH_SYNCLOGFILE);
                 // update comment thread for each story
                 if (count($itemlist) > 0) {
                     $lastItemTime = date('Y-m-d H:i:s', time() - 6 * 30 * 24 * 3600);
                     // set to six months earlier
                     foreach ($itemlist as $data) {
                         $temp = 'Bring over contentid' . $data[contentid] . ' Commentid' . $data[commentid] . '<br />';
                         // to do: if external story, then check for local userid and set here
                         $comment = $commentsObj->remoteSerialize($data);
                         if ($data[date] > $lastItemTime) {
                             $lastItemTime = $data[date];
                         }
                         $id = $commentsObj->add($comment);
                         echo $temp . '<br />';
                         var_dump($comment);
                         $this->db->log($temp, PATH_SYNCLOGFILE);
                         $this->db->log($comment, PATH_SYNCLOGFILE);
                     }
                 }
                 $this->db->update("cronJobs", "lastItemTime='{$lastItemTime}'", "id={$job->id}");
             }
             break;
         case 'syncScores':
             require_once 'content.class.php';
             $cObj = new content($this->db);
             $idList = $cObj->fetchRecentStoryList(14, 99, true);
             if ($idList != '') {
                 require_once 'apiCloud.class.php';
                 $apiObj = new apiCloud($this->db, $this->apiKey);
                 $resp = $apiObj->syncScores($this->cloudid, $idList, $this->timeStrToUnixModB($job->lastStart));
                 $itemlist = $resp[items];
                 //var_dump($resp);
                 if (count($itemlist) > 0) {
                     // update the score for each story with new votes
                     foreach ($itemlist as $data) {
                         $this->db->update("Content", "score={$data['score']}", "contentid={$data['contentid']}");
                         $temp = 'Set score of contentid:' . $data[contentid] . 'to ' . $data[score];
                         echo $temp . '<br />';
                         $this->db->log($temp, PATH_SYNCLOGFILE);
                     }
                 }
             }
             break;
         case 'syncResources':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             require_once 'resources.class.php';
             $resObj = new resources($this->db);
             $result = $apiObj->syncResources($this->cloudid);
             $resObj->sync(html_entity_decode($result[items][0][resources]));
             break;
         case 'updateSiteMap':
             $currentHour = date('G');
             // 0 - 24
             $currentDayOfWeek = date('w');
             // day of week 0-6
             $currentDayOfMonth = date('j');
             // day of month 1-31
             require_once 'siteMap.class.php';
             $smObj = new siteMap($this->db);
             // do always - build the map for content from the last hour
             $smObj->buildMap('hourly');
             // only do this as midnight
             if ($currentHour == 0) {
                 // map to all the content from the last day
                 $smObj->buildMap('daily');
             }
             // only do this at 3 am on first day of week
             if ($currentDayOfWeek = 0 and $currentHour == 3) {
                 // map to all the content from the last week, etc.
                 $smObj->buildMap('weekly');
             }
             // only do this at 2 am on first day of month
             if ($currentDayOfMonth == 1 and $currentHour == 2) {
                 $smObj->buildMap('monthly');
             }
             // call buildIndexMap after updating any individual child maps above
             // just the time stamps from each individual map file are updated in the indexmap
             // warning: if a individual map hasn't been built - the index map won't include a reference to it
             $smObj->buildIndexMap();
             break;
         case 'fetchFeeds':
             // import stories from feeds
             require_once 'feed.class.php';
             $feedObj = new feed($this->db);
             $feedObj->fetchBookmarks();
             $feedObj->fetchFeeds();
             $feedObj->fetchImages();
             if ($feedObj->newStoryLoaded) {
                 // update features
             }
             break;
         case 'logHourlyStats':
             require_once 'statistics.class.php';
             $statsObj = new statistics($this->db);
             $statsObj->logHourlyStats();
             break;
         case 'facebookMinifeed':
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             require_once PATH_FACEBOOK . '/classes/miniFeeds.class.php';
             $feedObj = new miniFeeds($this->db);
             $feedObj->loadFacebook($facebook);
             $feedObj->updateMiniFeeds();
             break;
         case 'facebookProfileBoxes':
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             require_once PATH_FACEBOOK . '/classes/profileBoxes.class.php';
             $proObj = new profileBoxes($this->db);
             $proObj->loadFacebook($facebook);
             $proObj->updateProfileBoxes();
             break;
         case 'facebookEmailEngine':
             // tbd
             break;
         case 'facebookAllocations':
             // check nightly facebook allocations
             $ssObj = new systemStatus($this->db);
             /* initialize the SMT Facebook appliation class, NO Facebook library */
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             $npd = $facebook->api_client->admin_getAllocation('notifications_per_day');
             $ssObj->setState('notifications_per_day', $npd);
             $ssObj->setState('announcement_notifications_per_week', $facebook->api_client->admin_getAllocation('announcement_notifications_per_week'));
             $ssObj->setState('requests_per_day', $facebook->api_client->admin_getAllocation('requests_per_day'));
             $ssObj->setState('emails_per_day', $facebook->api_client->admin_getAllocation('emails_per_day'));
             break;
         case 'facebookSendNotifications':
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             require_once PATH_FACEBOOK . "/classes/shareStories.class.php";
             $ssObj = new shareStories($app);
             $ssObj->processNotifications();
             break;
         case 'facebookSendPromos':
             /* not needed for now
             				if (date('G')==0) {
             					require_once PATH_FACEBOOK."/classes/promos.class.php";
             					$promoObj=new promos($this->db);				
             					$promoObj->send();
             				}			
             */
             break;
         case 'insertNewResearchData':
             require_once PATH_CORE . "/classes/researchRawSession.class.php";
             require_once PATH_CORE . "/classes/researchRawExtLink.class.php";
             require_once PATH_CORE . "/classes/researchSessionLength.class.php";
             require_once PATH_CORE . "/classes/researchLogDump.class.php";
             require_once PATH_CORE . "/classes/researchUserCollective.class.php";
             $rawExtLinkTable = new RawExtLinkTable($this->db);
             $rawExtLinkTable->insertNewestData();
             $rawSessionTable = new RawSessionTable($this->db);
             $rawSessionTable->insertNewestData();
             $sessionLengthTable = new SessionLengthTable($this->db);
             $sessionLengthTable->insertNewestData();
             $logDumpTable = new LogDumpTable($this->db);
             $logDumpTable->insertNewestData();
             $userCollectiveTable = new UserCollectiveTable($this->db);
             $userCollectiveTable->assimilateUsers();
             $stopAfterJob = true;
             break;
         case 'autoFeature':
             require_once PATH_CORE . '/classes/content.class.php';
             $cObj = new content($this->db);
             $cObj->autoFeature();
             break;
         case 'cleanup':
             require_once 'cleanup.class.php';
             $cleanObj = new cleanup($this->db, 'daily');
             break;
             // deprecated
         // deprecated
         case 'syncFeedList':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $result = $apiObj->syncFeedList($this->cloudid);
             require_once 'feed.class.php';
             $feedObj = new feed($this->db);
             $feedObj->syncFeedList($result[items]);
             break;
     }
     $execTime = microtime(true) - $startTime;
     $this->log('...completed in ' . $execTime . ' seconds.');
     $this->history[$this->cntJobs]['task'] = $job->task;
     $this->history[$this->cntJobs]['time'] = $execTime;
     $this->cntJobs += 1;
     $this->db->update("cronJobs", "nextRun=date_sub(NOW(), INTERVAL (0-{$job->freqMinutes}) MINUTE),lastExecTime={$execTime},lastStart='" . date('Y-m-d H:i:s', $startTime) . "',isRunning=0", "id={$job->id}");
     if ($stopAfterJob) {
         exit;
     }
 }
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     if ($params->getParam('res_id')) {
         $this->header = $lang->getMsg('resdata_header_change');
         $this->is_change = true;
     } else {
         $this->header = $lang->getMsg('resdata_header_new');
         $this->is_change = false;
     }
     $aItems = $categories->getThisAndBelow(1);
     $sJavaScriptArray = sprintf('new Array(%s)', implode(',', array_keys($aItems)));
     $this->sJavaScriptArray = $sJavaScriptArray;
     if ($_POST['resdata_isbn_submit'] && is_isbn($_POST['resdata_isbn'])) {
         foreach ($_POST as $key => $value) {
             if ($key != 'page' && $key != 'name' && $key != 'description' && $key != 'resdata_authors') {
                 $get .= $key . '=' . $value . '&';
             }
         }
         $this->switchPage('resdata&' . $get);
     }
     // Instantiate the HTML_QuickForm object
     $this->form = new formResData('ResDataForm', $params->getParam($res_id), $this->user);
     $this->new_res_link = false;
     // Try to validate a form
     if ($this->form->validate() && $this->form->exportValue('submit')) {
         $newres = new resources();
         if ($params->getParam('res_id')) {
             $newres->get($params->getParam('res_id'));
         }
         $newres->name = $this->form->exportValue('name');
         $newres->description = $this->form->exportValue('description');
         $newres->cat = $this->form->exportValue('resdata_cat');
         $newres->type = in_array($newres->cat, array_keys($aItems)) ? $this->form->exportValue('type') : 0;
         // insert/update in res-maintable
         if ($params->getParam('res_id')) {
             $newres->update();
         } else {
             $newres->since = time();
             $newres->user_id = $this->user->id;
             $newres->insert();
         }
         $newres->find(true);
         // insert/update in attributes-tables
         $attr_string = new attributesString();
         $attr_string->res_id = $newres->id;
         $attr_string->delete();
         $attr_select = new attributesSelect();
         $attr_select->res_id = $newres->id;
         $attr_select->delete();
         if ($params->getParam('cat')) {
             $cat = $params->getParam('cat');
             $attributes = new attributes();
             $attributes->category_id = $cat;
             if ($attributes->find()) {
                 while ($attributes->fetch()) {
                     if ($attributes->type == "string") {
                         $attr_string = new attributesString();
                         $attr_string->res_id = $newres->id;
                         $attr_string->attribute_id = $attributes->id;
                         // insert
                         $value = $this->form->exportValue('resdata_' . $attributes->name);
                         if ($value != "") {
                             $attr_string->value = $value;
                             $attr_string->insert();
                         }
                     }
                     if ($attributes->type == "select") {
                         $values = $this->form->getElementValue('resdata_' . $attributes->name);
                         if (!is_array($values)) {
                             $values = array($values);
                         }
                         foreach ($values as $value) {
                             if ($value[0] != 0) {
                                 $attr_string = new attributesSelect();
                                 $attr_string->res_id = $newres->id;
                                 $attr_string->attribute_id = $attributes->id;
                                 // insert
                                 $attr_string->value = $value[0];
                                 $attr_string->insert();
                             }
                         }
                     }
                 }
             }
         }
         // add res to pools if given
         $respools = new poolsResources();
         $respools->res_id = $newres->id;
         $respools->delete();
         $res_pools = $this->form->exportValue('free_pools');
         if (is_array($res_pools)) {
             foreach ($res_pools as $pool_id => $bool) {
                 if ($bool) {
                     $newres->addPool($pool_id);
                 }
             }
         }
         if ($params->getParam('res_id')) {
             $params->addParam('msg', 'msg_data_change_success', 'page');
             $this->switchPage('resmanager&function=all');
         } else {
             $this->form->removeElement('resdata_isbn_submit');
             $this->form->freezeForm();
             $this->addMsg('msg_res_insert_success');
             $this->new_res_link = true;
         }
     }
     if ($_POST['resdata_isbn_submit']) {
         $this->form->addRule('name', $lang->getMsg('resdata_form_namenecessary'), 'required');
         $this->form->addRule('resdata_cat', $lang->getMsg('resdata_form_catnecessary'), 'required');
     }
 }
<?php

/* initialize database and libraries */
define("INIT_COMMON", true);
define("INIT_PAGE", true);
define("INIT_SESSION", true);
include_once 'initialize.php';
require_once PATH_CORE . '/classes/resources.class.php';
$resObj = new resources($db);
/* begin building the page */
$page->setTitle('Resources');
$page->pkgStyles(CACHE_PREFIX . 'nrAbout', array(PATH_PHP_STYLES . '/newsroom.css', PATH_PHP_STYLES . '/tabs.css'));
$page->pkgScripts(CACHE_PREFIX . 'nrAbout', array());
$page->addToHeader($common->buildHeader() . $common->buildNavigation('Links'));
$page->addToFooter($common->buildFooter());
$page->addRSSFeed(URL_HOME . '?p=rss');
$code = '';
$code .= '<div id="pageBody">';
$code .= '<div id="pageContent">';
//$code.='<div id="colAlpha">';
$code .= $resObj->buildLinksColumn();
//$code.='</div><!-- end colAlpha -->';
//$code.='<div id="colBeta">';
//$code.=$resObj->buildLinksColumn('products');
//$code.='</div><!-- end colBeta -->';
$code .= '</div><!-- end pageContent -->';
$code .= '</div><!-- end pageBody -->';
$page->addToContent($code);
$page->display();
 private function process()
 {
     $this->commonProcess();
     $mail = services::getService('mail');
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     // use-res logics
     // accept inquiry
     if ($params->getParam('action') == 'wait_res_accept') {
         $wait_res = new resWait();
         $wait_res->get($params->getParam('wait_id'));
         $wait_res->fetchRes();
         // no item
         if ($wait_res->res->type == 0) {
             // delete all interessants
             $wait_res->res->deleteWaiting($wait_res->user_id);
             $wait_res->fetchUser();
             $wait_res->res->fetchUser();
             $mail->send('nogood_accepted', $wait_res->user, $wait_res->res, $wait_res->res->user);
             $this->switchPage('resmanager&msg=msg_request_success');
         }
         // give
         if ($wait_res->res->type == 1) {
             // res is given to the new owner
             $wait_res->res->changeOwner($wait_res->user_id);
             $wait_res->fetchUser();
             // delete pool affiliations
             $wait_res->res->deletePools();
             // delete all interessants
             $wait_res->res->deleteWaiting();
             $wait_res->res->fetchUser();
             $mail->send('give_accepted', $wait_res->user, $wait_res->res, $wait_res->res->user);
             $this->switchPage('resmanager&msg=msg_give_success');
         }
         // borrow
         if ($wait_res->res->type == 2) {
             // res is borrowed
             $wait_res->res->isBorrowed($wait_res->user_id);
             $wait_res->fetchUser();
             // delete all interessants
             $wait_res->res->deleteWaiting();
             $wait_res->res->fetchUser();
             $mail->send('borrow_accepted', $wait_res->user, $wait_res->res, $wait_res->res->user);
             $this->switchPage('resmanager&msg=msg_borrow_success');
         }
         $this->toDoList();
     }
     // refuse inquiry
     if ($params->getParam('action') == 'wait_res_refuse') {
         $wait_res = new resWait();
         $wait_res->id = $params->getParam('wait_id');
         $wait_res->find(true);
         $waiter = new user();
         $waiter->get($wait_res->user_id);
         $wait_res->fetchRes();
         $wait_res->res->fetchUser();
         $mail->send('refused', $waiter, $wait_res->res, $wait_res->res->user);
         $wait_res->delete();
         $this->toDoList();
         $this->switchPage('resmanager&');
     }
     // res is given back
     if ($params->getParam('action') == 'res_back') {
         $bow_res = new resBorrowed();
         $bow_res->res_id = $params->getParam('res_id');
         if ($bow_res->delete()) {
             $this->switchPage('resmanager&msg=msg_res_back');
         }
     }
     // delete resources
     if ($params->getParam('resdata_del_submit')) {
         foreach ($_POST as $res_id => $doesnmatter) {
             $del_res = new resources();
             // delete res
             $del_res->id = $res_id;
             if ($del_res->deleteAll()) {
                 $deleted = true;
             }
         }
         // set $msg
         if ($deleted) {
             $this->switchPage('resmanager&msg=msg_delres_success');
         }
     }
     $userres = new resFetcher();
     $userres->_order = "name";
     $userres->_user = $this->user->id;
     $userres->search();
     $this->userres = $userres->getAsArray();
     // function is set
     if ($this->res_offers) {
         $this->function = 'offers';
     } else {
         if ($this->borrowed_res) {
             $this->function = 'borrowed';
         } else {
             $this->function = 'all';
         }
     }
     if ($params->getParam('function')) {
         $this->function = $params->getParam('function');
     }
     if (!$this->res_offers && $this->function == 'offers') {
         $this->function = 'borrowed';
     }
     if (!$this->borrowed_res && $this->function == 'borrowed') {
         $this->function = 'all';
     }
 }
 function hasResources()
 {
     $resources = new resources();
     $resources->user_id = $this->id;
     if ($resources->find()) {
         return true;
     } else {
         return false;
     }
 }
 function formResData($name, $res_id = 0, $user)
 {
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $cats = services::getService('cats');
     $this->form($name);
     if ($params->getParam('res_id')) {
         $this->addElement('hidden', 'res_id', $params->getParam('res_id'));
         // Categories
         $this->addElement('select', 'resdata_cat', $lang->getMsg('resdata_form_category'), $cats->getAll(), array('onchange' => 'resdata_cat_change(this.value, document.ResDataForm.res_id.value)'));
     } else {
         $this->addElement('select', 'resdata_cat', $lang->getMsg('resdata_form_category'), $cats->getAll(), array('onchange' => 'resdata_cat_change_new(this.value)'));
     }
     $this->addElement('text', 'name', $lang->getMsg('resdata_form_name'), array('size' => 40, 'maxlength' => 255));
     $this->addElement('textarea', 'description', $lang->getMsg('resdata_form_description'), array('rows' => 7, 'cols' => 40));
     // fetch additional attributes e.g. form-fields for chosen category
     if ($params->getParam('cat')) {
         $cat = $params->getParam('cat');
         $this->addElement('hidden', 'cat', $cat);
         $attributes = new attributes();
         $attributes->category_id = $cat;
         if ($attributes->find()) {
             while ($attributes->fetch()) {
                 if ($attributes->type == "string") {
                     if ($attributes->name == "isbn") {
                         $this->addElement('text', 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), array('size' => 30, 'maxlength' => 255));
                         $this->addElement('submit', 'resdata_' . $attributes->name . '_submit', $lang->getMsg('resdata_form_' . $attributes->name . '_submit'), "asd");
                     } else {
                         $this->addElement('text', 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), array('size' => 30, 'maxlength' => 255));
                     }
                 }
                 if ($attributes->type == "select") {
                     $keys = new attributesSelectKeys();
                     $keys->attribute_id = $attributes->id;
                     $keys->find();
                     $options = array();
                     $options[0] = "----";
                     while ($keys->fetch()) {
                         $options[$keys->key] = $lang->getMsg('resdata_form_select_' . $keys->value);
                     }
                     sort($options);
                     $select_elements = array();
                     for ($i = 1; $attributes->amount >= $i; ++$i) {
                         $select_elements[] =& HTML_QuickForm::createElement('select', $i, null, $options);
                     }
                     $this->addGroup($select_elements, 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), ' ');
                 }
             }
         }
     }
     $this->addElement('select', 'type', $lang->getMsg('resdata_form_type'), array("2" => $lang->getMsg('resdata_form_type_borrow'), "1" => $lang->getMsg('resdata_form_type_give')));
     $free_pool = new poolsUser();
     $free_pool->user_id = $user->id;
     $free_pool->wait = 0;
     $free_pool->find();
     $free_pools = array();
     while ($free_pool->fetch()) {
         $free_pool->fetchPool();
         $free_pools[] =& HTML_QuickForm::createElement('checkbox', $free_pool->pool->id, null, ' ' . $free_pool->pool->name, $free_pool->pool->id);
     }
     $this->addGroup($free_pools, 'free_pools', $lang->getMsg('resdata_form_pools'), '<br>');
     $this->addElement('submit', 'submit', $lang->getMsg('resdata_form_submit'));
     // rules
     if (!$_POST['resdata_isbn_submit']) {
         $this->addRule('name', $lang->getMsg('resdata_form_namenecessary'), 'required');
         $this->addRule('resdata_cat', $lang->getMsg('resdata_form_catnecessary'), 'required');
     }
     // presets
     if ($params->getParam('resdata_isbn_submit') && is_isbn($params->getParam('resdata_isbn'))) {
         $lastletter = 0;
         $isbnfound = 0;
         $firstletter = substr($params->getParam('resdata_isbn'), 0, 1);
         if ($firstletter == 0 || $firstletter == 1) {
             $urlendings = array('com', 'co.uk', 'de', 'jp', 'fr', 'ca');
         } else {
             if ($firstletter == 2) {
                 $urlendings = array('fr', 'de', 'com', 'co.uk', 'jp', 'ca');
             } else {
                 if ($firstletter == 3) {
                     $urlendings = array('de', 'com', 'co.uk', 'jp', 'fr', 'ca');
                 } else {
                     if ($firstletter == 4) {
                         $urlendings = array('jp', 'de', 'com', 'co.uk', 'fr', 'ca');
                     } else {
                         $urlendings = array('com', 'co.uk', 'de', 'fr', 'ca', 'jp');
                     }
                 }
             }
         }
         $lastletters = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'x');
         foreach ($urlendings as $urlending) {
             foreach ($lastletters as $lastletter) {
                 if ($isbnfound == 0) {
                     $url = "http://ecs.amazonaws." . $urlending . "/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=1WFW5KS6EFZ0M8690ZR2&Operation=ItemLookup&ItemId=" . substr($params->getParam('resdata_isbn'), 0, 9) . $lastletter . "&ResponseGroup=Medium&type=lite&f=xml";
                     $xml = file_get_contents($url);
                     if (!strpos($xml, 'is not a valid value for ItemId')) {
                         $isbnfound = true;
                     }
                 }
             }
         }
         $first = strpos($xml, '<Item>') + 6;
         $sec = strpos($xml, '</Item>');
         $newxml = substr($xml, $first, $sec - $first);
         $newxml = unhtmlentities($newxml);
         // title
         $first = strpos($newxml, '<Title>') + 7;
         $sec = strpos($newxml, '</Title>');
         $title = substr($newxml, $first, $sec - $first);
         // binding
         $first = strpos($newxml, '<Binding>') + 9;
         $sec = strpos($newxml, '</Binding>');
         $binding = substr($newxml, $first, $sec - $first);
         // publisher
         $first = strpos($newxml, '<Label>') + 7;
         $sec = strpos($newxml, '</Label>');
         $publisher = substr($newxml, $first, $sec - $first);
         // publication date
         $first = strpos($newxml, '<PublicationDate>') + 17;
         $sec = strpos($newxml, '</PublicationDate>');
         $publicationdate = substr($newxml, $first, $sec - $first);
         // number of pages
         $first = strpos($newxml, '<NumberOfPages>') + 15;
         $sec = strpos($newxml, '</NumberOfPages>');
         $numberofpages = substr($newxml, $first, $sec - $first);
         // author(s)
         $authors = array();
         while (strstr($newxml, '<Author>')) {
             $first = strpos($newxml, '<Author>') + 8;
             $sec = strpos($newxml, '</Author>');
             $authors[] = substr($newxml, $first, $sec - $first);
             $newxml = substr($newxml, $sec + 9);
         }
         foreach ($authors as $key => $author) {
             if ($key != 0) {
                 $authors_field .= "; ";
             }
             $authors_field .= $this->changeAuthor($author);
         }
         // description
         $first = strpos($newxml, '<EditorialReviews><EditorialReview><Source>Aus der Amazon.de-Redaktion</Source><Content>') + 88;
         $sec = strpos($newxml, '</Content></EditorialReview></EditorialReviews>');
         $description = substr($newxml, $first, $sec - $first);
         $description = substr($description, 0, strrpos($description, '--'));
         // name
         if ($authors_field) {
             $name = $authors_field . ": " . $title;
         } else {
             $name = $title;
         }
         $this->setDefaults(array('resdata_title' => $title, 'name' => $name, 'description' => $description, 'resdata_authors' => $authors_field, 'resdata_binding' => $binding, 'resdata_number_of_pages' => $numberofpages, 'resdata_publication_date' => $publicationdate, 'resdata_publisher' => $publisher, 'resdata_isbn' => $params->getParam('resdata_isbn')));
     }
     if ($params->getParam('res_id')) {
         $free_pool = new poolsResources();
         $free_pool->res_id = $params->getParam('res_id');
         $free_pool->find();
         $free_pools_presets = array();
         while ($free_pool->fetch()) {
             $free_pools_presets[$free_pool->pool_id] = 1;
         }
         $changeform_res = new resources();
         $changeform_res->get($params->getParam('res_id'));
         $this->setDefaults(array('name' => $changeform_res->name, 'type' => $changeform_res->type, 'description' => $changeform_res->description, 'resdata_cat' => $changeform_res->cat, 'free_pools' => $free_pools_presets, 'public' => $changeform_res->is_public));
         // presets for additional fields
         if ($params->getParam('cat')) {
             $cat = $params->getParam('cat');
             $this->setDefaults(array('resdata_cat' => $cat));
             $attributes = new attributes();
             $attributes->category_id = $cat;
             if ($attributes->find()) {
                 while ($attributes->fetch()) {
                     if ($attributes->type == "string") {
                         $attr_string_presets = new attributesString();
                         $attr_string_presets->res_id = $params->getParam('res_id');
                         $attr_string_presets->attribute_id = $attributes->id;
                         $attr_string_presets->find(true);
                         $this->setDefaults(array('resdata_' . $attributes->name => $attr_string_presets->value));
                     }
                     if ($attributes->type == "select") {
                         $attr_select_presets = new attributesSelect();
                         $attr_select_presets->res_id = $params->getParam('res_id');
                         $attr_select_presets->attribute_id = $attributes->id;
                         $attr_select_presets->find();
                         $i = 1;
                         while ($attr_select_presets->fetch()) {
                             $this->setDefaults(array("resdata_" . $attributes->name . "[" . $i . "]" => $attr_select_presets->value));
                             ++$i;
                         }
                     }
                 }
             }
         }
     } else {
         if (isset($pool)) {
             $free_pools_presets[$pool->id] = 1;
             $this->setDefaults(array('type' => 2, 'public' => 0, 'free_pools' => $free_pools_presets));
         }
     }
     if ($params->getParam('cat')) {
         $this->setDefaults(array('resdata_cat' => $params->getParam('cat')));
     }
 }
 function inMine($user_id)
 {
     $in_mine = new resources();
     $in_mine->query('SELECT DISTINCT name FROM pools_resources, pools_pools_resources, pools_pools_user WHERE 
                    (pools_resources.id = ' . $this->id . ') AND 
                    (pools_pools_user.user_id = ' . $user_id . ') AND
                    (pools_pools_resources.res_id = pools_resources.id) AND 
                    (pools_pools_user.pool_id = pools_pools_resources.pool_id)');
     while ($in_mine->fetch()) {
         return true;
     }
     return false;
 }
 private function process()
 {
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $mail = services::getService('mail');
     // lost password
     if ($params->getParam('lostpassword') == 'true') {
         $this->lostpassword = true;
         $this->pwform = new formLostPassword('LostPassword');
         if ($this->pwform->validate()) {
             // write email
             $user = new user();
             $user->email = $this->pwform->exportValue('email');
             if ($user->find(true)) {
                 $mail->send('lostpassword', $user, $user->password);
                 $user->password = crypt($user->password, 'dl');
                 $user->update();
                 $this->switchPage('home&msg=msg_pw_sent');
             } else {
                 $this->switchPage('home&lostpassword=true&msg=msg_no_email');
             }
         }
     } else {
         // newsscript: write news
         if ($params->getParam('news') == 'writenews') {
             $newsform = new formNewsData("newsdata");
             if ($newsform->validate()) {
                 $new_news = new news();
                 $new_news->name = convertNewsSubmits($newsform->exportValue('newsname'));
                 $new_news->abstract = convertNewsSubmits($newsform->exportValue('newsabstract'));
                 $new_news->text = convertNewsSubmits($newsform->exportValue('newstext'));
                 $new_news->date = time();
                 $new_news->lang = $newsform->exportValue('newslang');
                 $new_news->insert();
                 $newsform->freezeForm();
                 $this->addMsg('msg_news_submitted');
             }
             $this->newsform = $newsform;
         }
     }
     // newsscript: show news headlines
     $shownews = new news();
     $shownews->lang = $lang->getLang();
     $shownews->orderBy('date DESC');
     $shownews->find();
     while ($shownews->fetch()) {
         $this->shownews[] = array('name' => $shownews->name, 'abstract' => $shownews->abstract, 'text' => $shownews->text, 'date' => date('d. m. Y', $shownews->date), 'id' => $shownews->id);
     }
     // Instantiate the HTML_QuickForm object
     $this->login_form = new formLogin('LoginForm');
     // count resources and pools
     $pool_count = new pools();
     $res_count = new resources();
     $pool_count->wait = 0;
     $pool_count->find();
     $res_count->find();
     $this->pool_count = 0;
     while ($pool_count->fetch()) {
         ++$this->pool_count;
     }
     $this->res_count = 0;
     while ($res_count->fetch()) {
         ++$this->res_count;
     }
     // Try to validate a form
     if ($this->login_form->validate()) {
         if (loginCorrect($this->login_form->exportValue('login'), $this->login_form->exportValue('loginpassword'))) {
             $session = services::getService('pageParams');
             if ($this->login_form->exportValue('remember')) {
                 setcookie('login', $this->login_form->exportValue('login'), time() + 60 * 60 * 24 * 365);
                 setcookie('password', $this->login_form->exportValue('loginpassword'), time() + 60 * 60 * 24 * 365);
             } else {
                 $session->addParam('login', $this->login_form->exportValue('login'), 'session');
                 $session->addParam('password', $this->login_form->exportValue('loginpassword'), 'session');
             }
             $session->addParam('msg', 'msg_login_correct', 'page');
             $this->switchPage('mysite');
         } else {
             $this->addMsg('msg_login_wrong');
         }
     } else {
         if (isset($this->user)) {
             $this->switchPage('mysite');
         }
     }
 }