query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } $cid = mysql_insert_id(); return $cid; } function getArticle($cid,$status=""){ global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "select a.*,b.name as section_name,b.body as section_body,b.display_type,c.name as category_name,c.body as category_body from articles a left join sections b on a.section_id = b.id left join sections c on a.category = c.id where cid = ?".(($status!="")?" and status = ?":""); $params = array($cid)+(($status!="")?array($status):array()); $result = $db->query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result->fetchRow(DB_FETCHMODE_ASSOC); } function editArticle($frm){ if (PEAR::isError($section = getSection($frm['section_id']))){ return $section; } if (!$section['articles']){ return PEAR::raiseError(getMessage(ERR_SECTION_ARTICLES_DISABLED)); } global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $publish_date = ( isset($frm['publish_date']['M']) && !empty($frm['publish_date']['M']) && isset($frm['publish_date']['d']) && !empty($frm['publish_date']['d']) && isset($frm['publish_date']['Y']) && !empty($frm['publish_date']['Y']) ) ? $frm['publish_date']['Y'] . '-' . $frm['publish_date']['M'] . '-' . $frm['publish_date']['d'] : null; $sql = "update articles set section_id=?,category=?,title=?,publish_date=?,teaser_text=?,body=?,modified_by=?,date_modified=NOW()". " where cid = ?"; $params = array( $frm['section_id'] ,$frm['category'] ,$frm['title'] ,date("Y-m-d",strtotime($publish_date)) ,$frm['teaser_text'] ,$frm['body'] ,$frm['modified_by'] ,$frm['cid'] ); $result = $db->query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } function getArticles($section_id,$status="",$limit=0){ global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "select a.*,b.name as section_name,b.body as section_body,c.name as category_name,c.body as category_body from articles a left join sections b on a.section_id = b.id left join sections c on a.category = c.id where section_id = ?".(($status!="")?" and status = ?":"")." order by date_modified,date_created".(($count > 0)?" limit ?":"").";"; $params = array($section_id)+(($status!="")?array($status):array())+(($count > 0)?array($count):array()); $result = $db->getAll($sql,$params,DB_FETCHMODE_ASSOC); prent($result); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } function deleteArticle($cid){ if (PEAR::isError($files = deleteArticleFiles($cid))) { return PEAR::raiseError(errorMessage(ERR_SYSTEM)); } global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "delete from articles where cid = ?"; $params = array($cid); $result = $db->query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } function deleteArticleFiles($id,$obj='article'){ global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "delete from files where _id = ? and _object = ?"; $params = array($id,$obj); $result = $db->query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } function changeArticleStatus($cid){ global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "update articles set status = not(status) where cid = ?"; $params = array($cid); $result = $db->query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } function changeArchiveState($cid){ global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "update articles set archive = not(archive) where cid = ?"; $params = array($cid); $result = $db->query($sql,$params); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } function getSectionArticles ($section_id,$count="",$status="",$archive="",$check_publish_date=true){ global $db; if (PEAR::isError($db)) { return PEAR::raiseError(getMessage(ERR_DB_CONNECT)); } $sql = "select * from articles where section_id in (".implode(",",$section_id).")".(($status)?" and status = ".$status:"").((!$archive)?" and archive = ".$archive:"").(($check_publish_date)?" and publish_date <= NOW()":"")." order by publish_date desc".(($count!="")?" limit ?":"").";"; $params = array(); if ($count!=""){ array_push($params,$count); } $result = $db->getAll($sql,$params,DB_FETCHMODE_ASSOC); if (PEAR::isError($result)) { return PEAR::raiseError(getMessage(ERR_DB)); } return $result; } ?>caching = false; $tpl->template_dir = SMARTY_TPL; $tpl->compile_dir = SMARTY_COMPILE; $tpl->cache_dir = SMARTY_CACHE; $tpl->assign("images_location",IMAGES_DIR); $tpl->assign("secured_url",SSL_PATH); $navigation = getNavigation(0); $tpl->assign("navigation",$navigation); $tpl->assign("banner",array('top'=>getSection(57),'left'=>getSection(56))); ?>register_function("isImage", "isImage"); function isImage($str) { if (ereg("image",$str)){ return true; } return false; } $tpl->register_function("collab_getStatus", "collab_getStatus"); function collab_getStatus($status) { $status_arr = array(0=>"draft",1=>"final"); echo $status_arr[$status]; return true; } $tpl->register_function("getSectionLink", "getSectionLink"); function getSectionLink($params){ $sid = getMainSection($params['id']); $arr = array(1=>"aboutus.php",2=>"whatwedo.php",3=>"mediacenter.php"); return $arr[$sid]; } require_once LIB_DIR.'lib-users.php'; $tpl->register_function("getUserRoleArticle", "getUserRoleArticle"); function getUserRoleArticle($params){ $user = getUser($params['id']); $role_arr = array("blogger"=>"[blog article]","admin"=>"[news article]","editor"=>"[blog article]"); return $role_arr[$user['role']]; } $tpl->register_function("isNewArticle", "isNewArticle"); function isNewArticle($date_created){ if (strtotime('-1 week') < strtotime($date_created)) return true; else return false; } $tpl->register_function("getArticleAuthor", "getArticleAuthor"); function getArticleAuthor($params){ if ($params['section'] == 27){ $user = getUser($params['uid']); $name = " by ".$user['firstname']." ".$user['lastname']; } return $name; } ?>