Location: PHPKode > projects > PhpProjectMaster > www/inc/comm.lib.php
<?php
/* 
 comm related functions
 (c) 2004-2007 by "Oleg Savchuk" <hide@address.com>

 part of phpProjectMaster project
 http://phpprojmaster.sourceforge.net

 The contents of this file are subject to the GNU GENERAL PUBLIC LICENSE
 http://www.gnu.org/copyleft/gpl.html
*/

 require_once "sitelib.php";
 require_once "form_utils.php";
 require_once "task.lib.php";

//preset module variables

 $comm_vars=array(
   'table_name'   => 'comm',
   'table_key_id' => 'comm_id',
 );

 $MAX_LINK_LENGTH=64;

//get item fields from database
function get_comm($item_id){
 global $comm_vars;

 $sql="select * from $comm_vars[table_name] where $comm_vars[table_key_id]=$item_id";
 return db_row($sql);
}

//mark item as removed
function delete_comm($item_id){
 global $comm_vars;

 db_query("update $comm_vars[table_name] set status=127 where $comm_vars[table_key_id]=$item_id");
}

//************ check access of logged user
// returns:
// 100 - full access: view, create, edit, delete + any other
// 40 - view+create+edit+delete
// 30 - view+create+edit
// 20 - view+create
// 10 - view only
// 0 - no access
function check_access_comm($item_id, $t_id=0, $p_id=0){
 #!!!TODO

 return 100;  //full access
}


//***************** send email to users about Task comment
function send_comm_new($comm_id){
 $hCOMM=get_comm($comm_id);
 $from_u_id=$hCOMM['add_u_id'];
 $hT=get_task($hCOMM['t_id']);

 $addrs=array();

 if ($from_u_id!=$hT['add_u_id']){  #if comm creator is not same as Task creator, add Task creator to email list
    $addrs[]=get_user($hT['add_u_id']);
 }
 if ($from_u_id!=$hT['u_id']){  #if comm creator is not same as Task Assignee, add Task Assignee to email list
    $addrs[]=get_user($hT['u_id']);
 }


 $EUSED=array();
 $add_u_id_name=get_user_name($from_u_id);
 foreach($addrs as $hTO){
    if ($EUSED[ $hTO['email'] ]) continue;
    $EUSED[ $hTO['email'] ]=1;

    $ps=array_merge($hCOMM,array(
      't_iname'       => $hT['iname'],
      'itype'         => $hT['itype'],
      'u_id_name'     => $hTO['fname'].' '.$hTO['lname'],
      'add_u_id_name' => $add_u_id_name,
      'ROOT_DOMAIN'   => $GLOBALS['root_domain'],
    ));
    $msg_body=parse_page("/emails", "new_comm.txt", $ps, 'v');
    $msg_body=preg_replace("/<[^>]*>/", "", $msg_body);  #remove HTML
//    rw($hTO['email']);
//     rw($msg_body);
    list($msg_subj, $msg_body)=email2subj_body($msg_body);

    send_email($hTO['email'], $msg_subj, $msg_body);
 }

// rwe('end');
}

//***************
function format_comm($text){
 global $root_url;

 //remove javascript attributes #!!!TODO check
 $text=preg_replace('/<[^>]*\s+on\w+=\"[^\"]+\"[^>]*>/si', "", $text);
 $text=preg_replace('/<[^>]*\s+on\w+=\'[^\']+\'[^>]*>/si', "", $text);
 $text=preg_replace("/javascript:/si", "", $text);

 //remove javascript
 $text=preg_replace("/<script[^>]*\/>/si", "", $text);
 $text=preg_replace("/<script[^>]*>.*?<\/script>/si", "", $text);

 //emboss links
 $text=preg_replace("/(\s+)(www\.[^\s]+)/si", "$1http://$2", $text);
 $text=preg_replace_callback("/([^\'\"\=])((?:http|ftp):\/\/[^\s\'\"<>\(\)]+)/si", 'link_replace_callback', $text);

 //[bug|task|idea] XX => link
 $text=preg_replace("/(\b(?:bug|task|idea)) +(\d+)/si", "<a href='$root_url/php/task.php?Edit=1&id=$2'>$1 $2</a>", $text);

 $text=n2br($text);
 return $text;
}

//*********** url replacer
// repalce long urls with shorter equivalent
//"$1<a href='$2' target='_blank'>$2</a>"
function link_replace_callback($matches){
 global $MAX_LINK_LENGTH;

 $url=$matches[2];
 $urlname=$url;
 if (strlen($urlname)>$MAX_LINK_LENGTH){
    $urlname=substr($url,0,$MAX_LINK_LENGTH/2)."...".substr($url,-$MAX_LINK_LENGTH/2);
 }

 return $matches[1]."<a href='$url' target='_blank'>".$urlname."</a>";
}


?>
Return current item: PhpProjectMaster