From 49b2955320c19e4e23097c66e438e51fdc70fc58 Mon Sep 17 00:00:00 2001 From: Paul Howarth Date: Mon, 11 Sep 2006 13:04:42 +0200 Subject: [PATCH] PHP5 notice cleanups This patch removes all of the remaining notices when running on PHP 5.1.4. Contagged should now run cleanly with error reporting on E_ALL. darcs-hash:20060911110442-df059-46a1680ffd06f4021129af3fc44535aa70fd7f5e.gz --- ajax.php | 6 +++--- entry.php | 21 +++++++++++++++------ functions.php | 18 ++++++++++++------ index.php | 16 ++++++++++++++-- login.php | 1 + tags.php | 3 ++- template.php | 19 ++++++++++++------- templates/list_entry.tpl | 3 ++- 8 files changed, 61 insertions(+), 26 deletions(-) diff --git a/ajax.php b/ajax.php index 564e59d..e26031b 100644 --- a/ajax.php +++ b/ajax.php @@ -4,11 +4,11 @@ ldap_login(); header('Content-Type: text/html; charset=utf-8'); -if($_REQUEST['taglookup']){ +if(!empty($_REQUEST['taglookup'])){ ajax_taglookup($_REQUEST['taglookup']); -}elseif($_REQUEST['addnote']){ +}elseif(!empty($_REQUEST['addnote'])){ ajax_addnote($_REQUEST['addnote'],$_REQUEST['note']); -}elseif($_REQUEST['settags']){ +}elseif(!empty($_REQUEST['settags'])){ ajax_settags($_REQUEST['settags'],$_REQUEST['tags']); } diff --git a/entry.php b/entry.php index c081da4..0b22eca 100644 --- a/entry.php +++ b/entry.php @@ -5,6 +5,7 @@ $users = get_users(); //select template to use + if (empty($_REQUEST['mode'])) { $_REQUEST['mode']='show'; } if( $_SESSION['ldapab']['username'] && ($_REQUEST['mode']=='edit' || $_REQUEST['mode']=='copy')){ $template='entry_edit.tpl'; @@ -14,11 +15,15 @@ $template='entry_show.tpl'; } - $dn = $_REQUEST['dn']; - #$dn = 'cn=bar foo, ou=contacts, o=cosmocode, c=de'; + if (empty($_REQUEST['dn'])) { + $dn = ""; + }else{ + $dn = $_REQUEST['dn']; + #$dn = 'cn=bar foo, ou=contacts, o=cosmocode, c=de'; + } //save data if asked for - if($_SESSION['ldapab']['username'] && $_REQUEST['save']){ + if($_SESSION['ldapab']['username'] && !empty($_REQUEST['save']) && $_REQUEST['save']){ // prepare special data $_REQUEST['entry']['jpegPhoto'][]=_getUploadData(); $_REQUEST['entry']['marker'] = explode(',',$_REQUEST['entry']['markers']); @@ -41,7 +46,7 @@ $smarty->assign('error','No dn was given'); $template = 'error.tpl'; } - }elseif($_REQUEST['del']){ + }elseif(!empty($_REQUEST['del']) && $_REQUEST['del']){ _delEntry($dn); }elseif(!_fetchData($dn)){ $smarty->assign('error',"The requested entry '$dn' was not found"); @@ -89,7 +94,7 @@ $entry = $result[0]; //remove dn from entry when copy - if($_REQUEST['mode'] == 'copy'){ + if(!empty($_REQUEST['mode']) && $_REQUEST['mode'] == 'copy'){ $entry['dn']=''; } @@ -101,6 +106,8 @@ print_r($entry); print '';*/ // make username from dn for manager: + if (empty($entry['manager'])) { $entry['manager']=array(""); } + if (empty($users[$entry['manager'][0]])) { $users[$entry['manager'][0]]=''; } $smarty->assign('managername',$users[$entry['manager'][0]]); return true; } @@ -116,7 +123,7 @@ print '';*/ $entries = namedentries(); $entries['mail']='mail'; //special field mail isn't in entries so we add it here if($conf['extended']){ - $entries['marker']='marker'; //same for marker inextended schema + $entries['marker']='marker'; //same for marker in extended schema } $entry = $_REQUEST['entry']; @@ -124,6 +131,7 @@ print '';*/ //construct new dn $now = time(); $newdn = 'uid='.$now; + if (empty($_REQUEST['type'])) { $_REQUEST['type']='public'; } if($_REQUEST['type'] == 'private'){ $newdn .= ', '.$conf['privatebook'].', '.$_SESSION['ldapab']['binddn']; }else{ @@ -158,6 +166,7 @@ print ''; if($key == 'dn'){ continue; }elseif(empty($entry[$key])){ + if (empty($_REQUEST['delphoto'])) { $_REQUEST['delphoto']=0; } if($key == 'jpegPhoto' && !$_REQUEST['delphoto']){ continue; } diff --git a/functions.php b/functions.php index 3f68561..afa2e43 100644 --- a/functions.php +++ b/functions.php @@ -25,7 +25,7 @@ function ldap_login(){ // use HTTP auth if wanted and possible $_SESSION['ldapab']['username'] = $_SERVER['PHP_AUTH_USER']; $_SESSION['ldapab']['password'] = $_SERVER['PHP_AUTH_PW']; - } elseif ($_COOKIE['ldapabauth']) { + } elseif (!empty($_COOKIE['ldapabauth'])) { // check persistent cookie $cookie = base64_decode($_COOKIE['ldapabauth']); $cookie = x_Decrypt($cookie,get_cookie_secret()); @@ -34,7 +34,8 @@ function ldap_login(){ $_SESSION['ldapab']['password'] = $p; } - if(!do_ldap_bind($_SESSION['ldapab']['username'], + if(empty($_SESSION['ldapab']) || + !do_ldap_bind($_SESSION['ldapab']['username'], $_SESSION['ldapab']['password'], $_SESSION['ldapab']['binddn'])){ header('Location: login.php?username='); @@ -111,6 +112,10 @@ function do_ldap_bind($user,$pass,$dn=""){ */ function auth_browseruid(){ $uid = ''; + if (empty($_SERVER['HTTP_USER_AGENT'])) { $_SERVER['HTTP_USER_AGENT']='USER_AGENT'; } + if (empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { $_SERVER['HTTP_ACCEPT_ENCODING']='ACCEPT_ENCODING'; } + if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $_SERVER['HTTP_ACCEPT_LANGUAGE']='ACCEPT_LANGUAGE'; } + if (empty($_SERVER['HTTP_ACCEPT_CHARSET'])) { $_SERVER['HTTP_ACCEPT_CHARSET']='ACCEPT_CHARSET'; } $uid .= $_SERVER['HTTP_USER_AGENT']; $uid .= $_SERVER['HTTP_ACCEPT_ENCODING']; $uid .= $_SERVER['HTTP_ACCEPT_LANGUAGE']; @@ -132,10 +137,10 @@ function set_session($user,$pass,$dn){ $_SESSION['ldapab']['password'] = $pass; $_SESSION['ldapab']['browserid'] = auth_browseruid(); - // (re)set the persistant auth cookie + // (re)set the persistent auth cookie if($user == ''){ setcookie('ldapabauth','',time()+60*60*24*365); - }elseif($_REQUEST['remember']){ + }elseif(!empty($_REQUEST['remember'])){ $cookie = serialize(array($user,$pass)); $cookie = x_Encrypt($cookie,get_cookie_secret()); $cookie = base64_encode($cookie); @@ -144,8 +149,8 @@ function set_session($user,$pass,$dn){ } /** - * Creates a random string to encrypt persistant auth - * cookies the string is stored inside the cache dir + * Creates a random string to encrypt persistent auth + * cookies; the string is stored inside the cache dir */ function get_cookie_secret(){ $file = dirname(__FILE__).'/cache/.htcookiesecret.php'; @@ -338,6 +343,7 @@ function get_users(){ $sr = ldap_list($LDAP_CON,$conf['usertree'],"ObjectClass=inetOrgPerson"); $result = ldap_get_binentries($LDAP_CON, $sr); + $users = array(); if(count($result)){ foreach ($result as $entry){ if(!empty($entry['sn'][0])){ diff --git a/index.php b/index.php index 8649ec6..72a84b0 100644 --- a/index.php +++ b/index.php @@ -14,12 +14,14 @@ $conf['privatebook'].','.$_SESSION['ldapab']['binddn'], $ldapfilter); $result2 = ldap_get_binentries($LDAP_CON, $sr); + }else{ + $result2 = ''; } $result = array_merge((array)$result1,(array)$result2); // select entry template - if($_REQUEST['export'] == 'csv'){ + if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){ $entrytpl = 'export_list_csv_entry.tpl'; }else{ $entrytpl = 'list_entry.tpl'; @@ -45,12 +47,15 @@ tpl_categories(); tpl_timezone(); tpl_country(); + if (empty($_REQUEST['filter'])) $_REQUEST['filter']=''; + if (empty($_REQUEST['marker'])) $_REQUEST['marker']=''; + if (empty($_REQUEST['search'])) $_REQUEST['search']=''; $smarty->assign('list',$list); $smarty->assign('filter',$_REQUEST['filter']); $smarty->assign('marker',$_REQUEST['marker']); $smarty->assign('search',$_REQUEST['search']); //display templates - if($_REQUEST['export'] == 'csv'){ + if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){ if ($conf['userlogreq'] == 1 && $user == '') { header("HTTP/1.1 401 ACCESS DENIED"); @@ -76,6 +81,8 @@ */ function _namesort($a,$b){ global $result; + if (empty($result[$a]['givenName'])) { $result[$a]['givenName']=''; } + if (empty($result[$b]['givenName'])) { $result[$b]['givenName']=''; } $x = $result[$a]['sn'][0].$result[$a]['givenName'][0]; $y = $result[$b]['sn'][0].$result[$b]['givenName'][0]; return(strcasecmp($x,$y)); @@ -88,6 +95,11 @@ function _makeldapfilter(){ //handle given filter + if (empty($_REQUEST['filter'])) { $_REQUEST['filter']=''; } + if (empty($_REQUEST['search'])) { $_REQUEST['search']=''; } + if (empty($_REQUEST['org'])) { $_REQUEST['org']=''; } + if (empty($_REQUEST['marker'])) { $_REQUEST['marker']=''; } + if (empty($_REQUEST['categories'])) { $_REQUEST['categories']=''; } $filter = ldap_filterescape($_REQUEST['filter']); $search = ldap_filterescape($_REQUEST['search']); $org = ldap_filterescape($_REQUEST['org']); diff --git a/login.php b/login.php index 96ba236..1e4b0d0 100644 --- a/login.php +++ b/login.php @@ -3,6 +3,7 @@ $msg = $lang['msg_login']; if(isset($_REQUEST['username'])){ + if (empty($_REQUEST['password'])) { $_REQUEST['password']=''; } if (do_ldap_bind($_REQUEST['username'],$_REQUEST['password'])){ //forward to next page if(!empty($_SESSION['ldapab']['lastlocation'])){ diff --git a/tags.php b/tags.php index 740c0aa..bd26632 100644 --- a/tags.php +++ b/tags.php @@ -19,9 +19,10 @@ $max = 0; $tags = array(); foreach ($result as $entry){ - if(count($entry['marker'])){ + if(!empty($entry['marker']) && count($entry['marker'])){ foreach($entry['marker'] as $marker){ $marker = strtolower($marker); + if (empty($tags[$marker])) { $tags[$marker]=0; } $tags[$marker] += 1; if($tags[$marker] > $max) $max = $tags[$marker]; } diff --git a/template.php b/template.php index e573166..f0fe1fa 100644 --- a/template.php +++ b/template.php @@ -35,11 +35,11 @@ function tpl_entry($in){ global $smarty; global $conf; $entries = namedentries(); - + $out=array(); //handle named entries foreach(array_keys($entries) as $key){ - if($in[$key]){ + if(!empty($in[$key])){ if(is_array($in[$key])){ $out[$entries[$key]] = $in[$key][0]; }else{ @@ -49,7 +49,8 @@ function tpl_entry($in){ } //set the type - $out['dn'] = normalize_dn($out['dn']); + if (empty($out['dn'])) { $out['dn']=''; } + $out['dn'] = normalize_dn($out['dn']); $conf['publicbook'] = normalize_dn($conf['publicbook']); if($out['dn']){ if(strstr($out['dn'],$conf['publicbook'])){ @@ -59,15 +60,17 @@ function tpl_entry($in){ } } - //mail entries are handled special + //mail entries are handled specially + if (empty($in['mail'])) { $in['mail']=''; } $out['mail'] = $in['mail']; if ($conf['extended']){ - //handle marker special in extended mode + //handle marker specially in extended mode + if (empty($in['marker'])) { $in['marker']=''; } $out['marker'] = $in['marker']; if(is_array($in['marker'])) $out['markers'] = join(', ',$in['marker']); } if ($conf['openxchange']){ - //handle categories special in openxchange mode + //handle categories specially in openxchange mode $out['categories'] = $in['OXUserCategories']; } @@ -116,12 +119,14 @@ function tpl_markers(){ $conf['privatebook'].','.$_SESSION['ldapab']['binddn'], "ObjectClass=inetOrgPerson",array("marker")); $result2 = ldap_get_binentries($LDAP_CON, $sr); + }else{ + $result2 = ''; } $result = array_merge((array)$result1,(array)$result2); if(count($result)){ foreach ($result as $entry){ - if(count($entry['marker'])){ + if(!empty($entry['marker']) && count($entry['marker'])){ foreach($entry['marker'] as $marker){ array_push($markers, $marker); } diff --git a/templates/list_entry.tpl b/templates/list_entry.tpl index c1e5759..e6a9ed5 100644 --- a/templates/list_entry.tpl +++ b/templates/list_entry.tpl @@ -1,3 +1,4 @@ +{if $entry.type} @@ -22,4 +23,4 @@ {/if} - +{/if} -- 2.39.5