From d20e4cb32ea6dd6b3f21b0f9f3106d046d39d9c5 Mon Sep 17 00:00:00 2001 From: paulr Date: Wed, 27 Apr 2011 00:22:47 +1000 Subject: [PATCH] moved some stuff back to lib from plugins --- doc/globals.txt | 4 + lib/datastore.php | 180 +++++++++++++++++++++++++++++++++++++++++++++ lib/db.php | 123 ++++++++++++++++++++++++++++++ lib/lib.php | 3 +- lib/messages.php | 73 ++++++++++++++++++ lib/plugins/datastore.php | 135 --------------------------------- lib/plugins/db.php | 123 ------------------------------ lib/plugins/messages.php | 73 ------------------ lib/plugins/www.php | 167 ----------------------------------------- lib/www.php | 169 ++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 551 insertions(+), 499 deletions(-) create mode 100644 lib/datastore.php create mode 100644 lib/db.php create mode 100644 lib/messages.php delete mode 100644 lib/plugins/datastore.php delete mode 100644 lib/plugins/db.php delete mode 100644 lib/plugins/messages.php delete mode 100644 lib/plugins/www.php create mode 100644 lib/www.php diff --git a/doc/globals.txt b/doc/globals.txt index e77fa2d..49b5a27 100644 --- a/doc/globals.txt +++ b/doc/globals.txt @@ -4,5 +4,9 @@ $BASE_URLS["ypc"]["function"] = "yp_contentUrlsCtl"; $MENU_ITEMS["yp"]["title"] = "YUM Proxy"; $MENU_ITEMS["yp"]["link"] = "/ypc/proxycontrol"; +$VERSION["item"]["major"] +$VERSION["item"]["minor"] +$VERSION["item"]["release"] + $GLOBAL_BASE_URL="/src/eclipse-workspace/glcas/www/"; $DB_URL="sqlite:$BASE_DIR/var/ds_store.db"; diff --git a/lib/datastore.php b/lib/datastore.php new file mode 100644 index 0000000..a074cc3 --- /dev/null +++ b/lib/datastore.php @@ -0,0 +1,180 @@ +Browsing, $dsbr
"; + break; + case "createds": + ds_createDS($_REQUEST["dsname"], $_REQUEST["dsloc"]); + echo "DS Created, return"; + break; + case "control": + default: + ds_controlPane(); + // go thru the db and list the components + } + } +} + +function ds_controlPane() +{ + global $GLOBAL_BASE_URL; + echo "

DataStores

"; + $dss = ds_listDS(); + + if($dss != false) { + echo ""; + echo ""; + foreach($dss as $dsl) { + $dsname = $dsl["dsname"]; + $dspath = $dsl["dslocation"]; + echo ""; + } + echo "
DataStore NameDataStore PathSizeUsageControl
$dsname$dspath
"; + } + echo "

Create DataStore

"; + echo "
"; + echo "DataStore Name:
"; + echo "DataStore Location:
"; + echo ""; + echo "
"; + +} + +function ds_leftMenu() +{ + global $GLOBAL_BASE_URL; + echo "

Browse

"; + $dss = ds_listDS(); + //echo "
";
+	//print_r($dss);
+	//echo "
"; + foreach ($dss as $dsl) { + $dsname = $dsl["dsname"]; + echo "$dsname
"; + } +} + +function ds_contentUrls() +{ + $calls["needs_base_page"] = true; + $calls["content_pane_function"] = "ds_contentPane"; + $calls["left_menu_function"] = "ds_leftMenu"; + + return $calls; +} + +function ds_createDS($ds_name, $store_location) +{ + db_createTable("datastores", "dsname", "dslocation"); + db_createTable("datastores_files", "dsname", "fileowner", "filename", "dsfname"); + + $data = db_selectData("datastores", "dsname", "$ds_name"); + if(isset($data[0]["dsname"])) return false; + + db_insertData("datastores", "$ds_name", "$store_location"); +} + +function ds_listDS() +{ + return db_selectData("datastores"); +} + +function ds_deleteFile($ds_name, $file_name, $file_tag) +{ + $dlk = db_selectData("datastores_files", "filename", $file_name); + $afname = ""; + foreach($dlk as $kmm) { + if($kmm["fileowner"] == $file_tag) { + // we got ya + $afname = $kmm["dsfname"]; + if(file_exists($afname)) unlink($afname); + //echo "name was: $afname\n"; + } + } + //echo "now delete name was: $afname\n"; + if($afname != "") db_deleteData("datastores_files", "dsfname", $afname); +} + +// returns a file name to the location a file can be created +function ds_fileds($ds_name, $file_name, $file_tag) +{ + + $data = db_selectData("datastores", "dsname", "$ds_name"); + + $dtime = time(); + $made_file_name = "$dtime-".md5($file_name)."-".basename($file_name); + + $act_fname = $data[0]["dslocation"]."/".basename($made_file_name); + + db_insertData("datastores_files", "$ds_name", "$file_tag", "$file_name", "$act_fname"); + + return $act_fname; +} + +function ds_getFileList($ds_name, $file_tag) +{ + $list = db_selectData("datastores_files", "fileowner", "$file_tag"); + + return $list; +} + + +function ds_deleteDS($ds_name) +{ + db_deleteData("datastores", "dsname", "$ds_name"); + db_deleteData("datastores_files", "dsname", $ds_name); +} + +function ds_downloadAndStore($ds_name, $file_id, $file_name, $file_url) +{ + +} + +?> \ No newline at end of file diff --git a/lib/db.php b/lib/db.php new file mode 100644 index 0000000..f24917f --- /dev/null +++ b/lib/db.php @@ -0,0 +1,123 @@ +query($sql); +} + +function db_insertData($tablename) +{ + + $db = db_getDB(); + + $sql = "insert into \"$tablename\" values (NULL"; + for($i=1; $i < func_num_args(); $i++) { + $sql .= ",'".func_get_arg($i)."'"; + } + $sql .=")"; + + $db->query($sql); +} + +function db_selectData($tablename, $column="", $value="") +{ + $db = db_getDB(); + + if($column != "") $extra = " where $column like '%$value%'"; + else $extra = ""; + $sql = "select * from \"$tablename\"$extra"; + $res = $db->query($sql); + if(!$res) return false; + $data = $res->fetchAll(); + + return $data; +} + +function db_deleteData($tablename, $column, $value) +{ + $db = db_getDB(); + + $sql = "delete from \"$tablename\" where $column like '%$value%'"; + //echo "Sql is $sql\n"; + return $db->query($sql); + +} + +function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true) +{ + $db = db_getDB(); + + if($exact) $sql = "update \"$tablename\" set $column='$newdata' where $wherecol='$wheredata'"; + else $sql = "update \"$tablename\" set $column='$newdata' where $wherecol like '$wheredata'"; + return $db->query($sql); +} + +function db_deleteTable($tablename) +{ + $db = db_getDB(); + + $sql = "drop table $tablename"; + + return $db->query($sql); +} + +function db_tableExists($tablename) +{ + $db = db_getDB(); + + $sql = "select count(*) from sqlite_master where type='table' and name='$tablename'"; + $res = $db->query($sql); + + $value = $res->fetchColumn(); + + if($value == 1) return true; + else return false; +} + +function db_getTables() +{ + $db = db_getDB(); + + $sql = "select name from sqlite_master where type='table' and name not like 'sqlite_%'"; + $res = $db->query($sql); + + return $res->fetchAll(); +} +?> \ No newline at end of file diff --git a/lib/lib.php b/lib/lib.php index e446b09..63462fe 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -2,7 +2,8 @@ require_once("config.php"); require_once("wsdl.php"); - +require_once("www.php"); +require_once("db.php"); // first and foremost, load the plugins $basedir = dirname(__FILE__); diff --git a/lib/messages.php b/lib/messages.php new file mode 100644 index 0000000..e735e90 --- /dev/null +++ b/lib/messages.php @@ -0,0 +1,73 @@ + \ No newline at end of file diff --git a/lib/plugins/datastore.php b/lib/plugins/datastore.php deleted file mode 100644 index db51d36..0000000 --- a/lib/plugins/datastore.php +++ /dev/null @@ -1,135 +0,0 @@ -Browsing, $dsbr
"; - break; - case "createds": - ds_createDS($_REQUEST["dsname"], $_REQUEST["dsloc"]); - echo "DS Created, return"; - break; - case "control": - default: - ds_controlPane(); - // go thru the db and list the components - } - } -} - -function ds_controlPane() -{ - echo ""; - echo ""; - - echo "
DataStore NameDataStore PathSizeUsageControl
"; - echo "
"; - echo "DataStore Name: "; - echo "DataStore Location: "; - echo ""; - echo "
"; - -} - -function ds_leftMenu() -{ - global $GLOBAL_BASE_URL; - echo "Browse
"; - $dss = ds_listDS(); - //echo "
";
-	//print_r($dss);
-	//echo "
"; - foreach ($dss as $dsl) { - $dsname = $dsl["dsname"]; - echo "$dsname
"; - } -} - -function ds_contentUrls() -{ - $calls["needs_base_page"] = true; - $calls["content_pane_function"] = "ds_contentPane"; - $calls["left_menu_function"] = "ds_leftMenu"; - - return $calls; -} - -function ds_createDS($ds_name, $store_location) -{ - db_createTable("datastores", "dsname", "dslocation"); - db_createTable("datastores_files", "dsname", "fileowner", "filename", "dsfname"); - - $data = db_selectData("datastores", "dsname", "$ds_name"); - if(isset($data[0]["dsname"])) return false; - - db_insertData("datastores", "$ds_name", "$store_location"); -} - -function ds_listDS() -{ - return db_selectData("datastores"); -} - -function ds_deleteFile($ds_name, $file_name, $file_tag) -{ - $dlk = db_selectData("datastores_files", "filename", $file_name); - $afname = ""; - foreach($dlk as $kmm) { - if($kmm["fileowner"] == $file_tag) { - // we got ya - $afname = $kmm["dsfname"]; - if(file_exists($afname)) unlink($afname); - //echo "name was: $afname\n"; - } - } - //echo "now delete name was: $afname\n"; - if($afname != "") db_deleteData("datastores_files", "dsfname", $afname); -} - -// returns a file name to the location a file can be created -function ds_fileds($ds_name, $file_name, $file_tag) -{ - - $data = db_selectData("datastores", "dsname", "$ds_name"); - - $dtime = time(); - $made_file_name = "$dtime-".md5($file_name)."-".basename($file_name); - - $act_fname = $data[0]["dslocation"]."/".basename($made_file_name); - - db_insertData("datastores_files", "$ds_name", "$file_tag", "$file_name", "$act_fname"); - - return $act_fname; -} - -function ds_getFileList($ds_name, $file_tag) -{ - $list = db_selectData("datastores_files", "fileowner", "$file_tag"); - - return $list; -} - - -function ds_deleteDS($ds_name) -{ - db_deleteData("datastores", "dsname", "$ds_name"); - db_deleteData("datastores_files", "dsname", $ds_name); -} - -function ds_downloadAndStore($ds_name, $file_id, $file_name, $file_url) -{ - -} - -?> \ No newline at end of file diff --git a/lib/plugins/db.php b/lib/plugins/db.php deleted file mode 100644 index f24917f..0000000 --- a/lib/plugins/db.php +++ /dev/null @@ -1,123 +0,0 @@ -query($sql); -} - -function db_insertData($tablename) -{ - - $db = db_getDB(); - - $sql = "insert into \"$tablename\" values (NULL"; - for($i=1; $i < func_num_args(); $i++) { - $sql .= ",'".func_get_arg($i)."'"; - } - $sql .=")"; - - $db->query($sql); -} - -function db_selectData($tablename, $column="", $value="") -{ - $db = db_getDB(); - - if($column != "") $extra = " where $column like '%$value%'"; - else $extra = ""; - $sql = "select * from \"$tablename\"$extra"; - $res = $db->query($sql); - if(!$res) return false; - $data = $res->fetchAll(); - - return $data; -} - -function db_deleteData($tablename, $column, $value) -{ - $db = db_getDB(); - - $sql = "delete from \"$tablename\" where $column like '%$value%'"; - //echo "Sql is $sql\n"; - return $db->query($sql); - -} - -function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true) -{ - $db = db_getDB(); - - if($exact) $sql = "update \"$tablename\" set $column='$newdata' where $wherecol='$wheredata'"; - else $sql = "update \"$tablename\" set $column='$newdata' where $wherecol like '$wheredata'"; - return $db->query($sql); -} - -function db_deleteTable($tablename) -{ - $db = db_getDB(); - - $sql = "drop table $tablename"; - - return $db->query($sql); -} - -function db_tableExists($tablename) -{ - $db = db_getDB(); - - $sql = "select count(*) from sqlite_master where type='table' and name='$tablename'"; - $res = $db->query($sql); - - $value = $res->fetchColumn(); - - if($value == 1) return true; - else return false; -} - -function db_getTables() -{ - $db = db_getDB(); - - $sql = "select name from sqlite_master where type='table' and name not like 'sqlite_%'"; - $res = $db->query($sql); - - return $res->fetchAll(); -} -?> \ No newline at end of file diff --git a/lib/plugins/messages.php b/lib/plugins/messages.php deleted file mode 100644 index e735e90..0000000 --- a/lib/plugins/messages.php +++ /dev/null @@ -1,73 +0,0 @@ - \ No newline at end of file diff --git a/lib/plugins/www.php b/lib/plugins/www.php deleted file mode 100644 index 3d5b9d1..0000000 --- a/lib/plugins/www.php +++ /dev/null @@ -1,167 +0,0 @@ -"; - - // top - if(isset($calls["top_function"])) { - $func = $calls["top_function"]; - $func(); - } else { - www_top(); - } - - echo ""; - - // left menu - if(isset($calls["left_menu_function"])) { - $func = $calls["left_menu_function"]; - $func(); - } else { - www_leftmenu(); - } - - echo ""; - - // contentpane - if(isset($calls["content_pane_function"])) { - $func = $calls["content_pane_function"]; - $func(); - } else { - www_contentpane(); - } - - echo ""; - - // footer - if(isset($calls["footer_function"])) { - $func = $calls["footer_function"]; - $func(); - } else { - www_footer(); - } - - echo ""; - - // page end - if(isset($calls["page_end_function"])) { - $func = $calls["page_end_function"]; - $func(); - } else { - www_pageend(); - } - -} - -function www_header() -{ - echo ""; -} - -function www_top() -{ - echo "

Welcome to GLCAS

"; - echo ""; - - global $MENU_ITEMS, $GLOBAL_BASE_URL; - foreach($MENU_ITEMS as $mes) { - $mtext = $mes["title"]; - $mlink = "$GLOBAL_BASE_URL/".$mes["link"]; - // remove the excess /'s - $mlink2 = preg_replace("/\/[\/]+/", "/", $mlink); - //echo "went from $mlink to $mlink2\n"; - echo ""; - } - - echo "
$mtext
"; - if(function_exists("msg_haveMessages")) if(msg_haveMessages()) { - echo ""; - $msgs = msg_getMessages(); - - foreach($msgs as $msg) { - $msgtime = msg_toDate($msg["msgdate"]); - $msgcol = $msg["msgcolour"]; - $msgtxt = $msg["msgtext"]; - $msgid = $msg["messages_id"]; - - echo ""; - echo ""; - } - echo "
$msgtime - $msgtxtAcknowledge
"; - } -} - -function www_leftmenu() -{ - echo "i be a left menu, yar"; -} - -function www_contentpane() -{ - echo "i be a content pane, yar"; -} - -function www_footer() -{ - echo "i be a footer, yar"; -} - - -function www_pageend() -{ - echo ""; -} - -function urlCreate($from) -{ - global $MENU_ITEMS, $GLOBAL_BASE_URL; - - $mlink = "$GLOBAL_BASE_URL/".$from; - $mlink = preg_replace("/\/[\/]+/", "/", $mlink); - - return $mlink; - -} - - -?> \ No newline at end of file diff --git a/lib/www.php b/lib/www.php new file mode 100644 index 0000000..f356ca0 --- /dev/null +++ b/lib/www.php @@ -0,0 +1,169 @@ +"; + + // top + if(isset($calls["top_function"])) { + $func = $calls["top_function"]; + $func(); + } else { + www_top(); + } + + echo ""; + + // left menu + if(isset($calls["left_menu_function"])) { + $func = $calls["left_menu_function"]; + $func(); + } else { + www_leftmenu(); + } + + echo ""; + + // contentpane + if(isset($calls["content_pane_function"])) { + $func = $calls["content_pane_function"]; + $func(); + } else { + www_contentpane(); + } + + echo ""; + + // footer + if(isset($calls["footer_function"])) { + $func = $calls["footer_function"]; + $func(); + } else { + www_footer(); + } + + echo ""; + + // page end + if(isset($calls["page_end_function"])) { + $func = $calls["page_end_function"]; + $func(); + } else { + www_pageend(); + } + +} + +function www_header() +{ + echo ""; + echo " "; + echo ""; +} + +function www_top() +{ + echo "

Welcome to GLCAS

"; + echo ""; + + global $MENU_ITEMS, $GLOBAL_BASE_URL; + foreach($MENU_ITEMS as $mes) { + $mtext = $mes["title"]; + $mlink = "$GLOBAL_BASE_URL/".$mes["link"]; + // remove the excess /'s + $mlink2 = preg_replace("/\/[\/]+/", "/", $mlink); + //echo "went from $mlink to $mlink2\n"; + echo ""; + } + + echo "
$mtext
"; + if(function_exists("msg_haveMessages")) if(msg_haveMessages()) { + echo ""; + $msgs = msg_getMessages(); + + foreach($msgs as $msg) { + $msgtime = msg_toDate($msg["msgdate"]); + $msgcol = $msg["msgcolour"]; + $msgtxt = $msg["msgtext"]; + $msgid = $msg["messages_id"]; + + echo ""; + echo ""; + } + echo "
$msgtime - $msgtxtAcknowledge
"; + } +} + +function www_leftmenu() +{ + echo "i be a left menu, yar"; +} + +function www_contentpane() +{ + echo "i be a content pane, yar"; +} + +function www_footer() +{ + echo "i be a footer, yar"; +} + + +function www_pageend() +{ + echo ""; +} + +function urlCreate($from) +{ + global $MENU_ITEMS, $GLOBAL_BASE_URL; + + $mlink = "$GLOBAL_BASE_URL/".$from; + $mlink = preg_replace("/\/[\/]+/", "/", $mlink); + + return $mlink; + +} + + +?> \ No newline at end of file -- 1.7.0.4