From: Roland, R. M <rmr...@in...> - 2003-10-14 19:48:42
|
I wrote a function to return information on branches. =20 I'm going to submit the code here and let the dev team decide where, if = anywhere, they want to put it in the codebase.=20 =20 I used commas to separate list items, so if someone sees the need to = support a branchname with commas in it, then let me know and I'll use a = different separator, otherwise, I don't see it as a problem. =20 Thanks,=20 Ryan Roland=20 Application Developer=20 Information Technology=20 Division of Recreational Sports=20 Indiana University =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D /* * Function branch_info will return a 2D associative array * of information on different branches that exist in your * instance of phpws. Order of fields and branches is <b>not</b> * important since returned array is associative. * * @author Ryan Roland < rmr...@NO...> * @param string $branch_name comma separated list of branches to = return information on (or "all") * @param string $desired_info comma separated list of information = fields to return (or "all") * @return array 2D associative array with requested information on = requested branches */ function branch_info($branch_name=3D"all",$desired_info=3D"all"){ // create sql for specified branches $sql =3D "SELECT * FROM " . $GLOBALS["core"]->tbl_prefix . = "branch_sites"; if ($branch_name !=3D "all") { $branches =3D explode(",",$branch_name); $addon =3D " WHERE 1=3D0 "; foreach ($branches as $next_branch){ $addon .=3D " OR branchName=3D'" . $next_branch . "'"; } $sql .=3D $addon; } // get DB data on specified branches $result =3D $GLOBALS["core"]->getAll($sql); // array of desired information $return_info =3D array(); if(!DB::isError($result) && is_array($result) && sizeof($result) > 0) = { $all_file_items =3D = array("dbversion","dbhost","dbuser","dbpass","dbname","table_prefix"); $all_db_items =3D = array("branchName","configFile","IDhash","branchDir","branchHttp"); // create list of desired items if ($desired_info =3D=3D "all"){ $file_items =3D $all_file_items; $db_itesm =3D $all_db_itesm; } else{ $info_types =3D explode(",",$desired_info); $file_items =3D array_intersect($all_file_items, $info_types); $db_items =3D array_intersect($all_db_items, $info_types); } // loop through each branch gathering info foreach ($result as $branch){ $return_info[$branch["branchName"]] =3D array(); if (sizeof($db_items) > 0){ foreach ($db_items as $type){ switch($type){ case "branchName": $return_info[$branch["branchName"]]["branchName"] =3D = $branch["branchName"]; break; case "configFile": $return_info[$branch["branchName"]]["configFile"] =3D = $branch["configFile"]; break; case "IDhash": $return_info[$branch["branchName"]]["IDhash"] =3D = $branch["IDhash"]; break; case "branchDir": $return_info[$branch["branchName"]]["branchDir"] =3D = $branch["branchDir"]; break; case "branchHttp": $return_info[$branch["branchName"]]["branchHttp"] =3D = $branch["branchHttp"]; break; }// end switch }// end foreach }// end if if (sizeof($file_items) > 0){ // include the config file for each branch to get additional = info include_once($GLOBALS["core"]->source_dir . "conf/branch/" . = $branch["configFile"]); foreach ($file_items as $type){ switch($type){ case "dbversion": $return_info[$branch["branchName"]]["dbversion"] =3D = $dbversion; break; case "dbhost": $return_info[$branch["branchName"]]["dbhost"] =3D $dbhost; break; case "dbuser": $return_info[$branch["branchName"]]["dbuser"] =3D $dbuser; break; case "dbpass": $return_info[$branch["branchName"]]["dbpass"] =3D $dbpass; break; case "dbname": $return_info[$branch["branchName"]]["dbname"] =3D $dbname; break; case "table_prefix": $return_info[$branch["branchName"]]["table_prefix"] =3D = $table_prefix; break; }// end switch }// end foreach }// end if }// end foreach }// end if return $return_info; }//END FUNC branch_info =20 =20 |