[opw-web] Move build_organization_select() to new utils.php



commit 52deba9f3ab34571a522692fc2d961ffc27527c7
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sun Mar 9 12:48:11 2014 -0400

    Move build_organization_select() to new utils.php

 init.php                      |    3 +++
 modules/mod_view_projects.php |   32 --------------------------------
 utils.php                     |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 32 deletions(-)
---
diff --git a/init.php b/init.php
index f813fbc..ac68bba 100644
--- a/init.php
+++ b/init.php
@@ -46,6 +46,9 @@ $skin   = new skin();
 $module = new module();
 $donut  = new donut();
 
+// Random utilities
+include_once('utils.php');
+
 // Always use https
 #if ($core->get_protocol() == 'http://')
 #{
diff --git a/modules/mod_view_projects.php b/modules/mod_view_projects.php
index be85c64..e074b06 100644
--- a/modules/mod_view_projects.php
+++ b/modules/mod_view_projects.php
@@ -96,38 +96,6 @@ else
     $is_owner = false;
 }
 
-function build_organization_select($program_id, $current, $include_other)
-{
-    global $db, $lang;
-
-    $sql = "SELECT * FROM {$db->prefix}organizations " .
-               "WHERE program_id = ?";
-    $list_data = $db->query($sql, $program_id);
-
-    $option_name = $lang->get('select_organization');
-    $organization_select = "<select name='o'>";
-
-    $selected = $current == 0 ? " selected" : "";
-    $organization_select .= "<option value='0'$selected>{$option_name}</option>";
-
-    foreach ($list_data as $row)
-      {
-        $organization_title = htmlspecialchars($row['title']);
-        $id = $row['id'];
-        $selected = $current == $id ? " selected" : "";
-        $organization_select .= "<option value='$id'$selected>{$organization_title}</option>";
-      }
-
-    $option_name = $lang->get('other');
-    if ($include_other) {
-        $selected = $current == -1 ? " selected" : "";
-        $organization_select .= "<option value='-1'$selected>{$option_name}</option>";
-    }
-    $organization_select .= "</select>";
-
-    return $organization_select;
-}
-
 // Serve the page based on the action
 if ($action == 'editor')
 {
diff --git a/utils.php b/utils.php
new file mode 100644
index 0000000..c1b48c6
--- /dev/null
+++ b/utils.php
@@ -0,0 +1,35 @@
+<?php
+function build_organization_select($program_id, $current, $include_other, $name="o", $id=null)
+{
+    global $db, $lang;
+
+    $sql = "SELECT * FROM {$db->prefix}organizations " .
+               "WHERE program_id = ?";
+    $list_data = $db->query($sql, $program_id);
+
+    $option_name = $lang->get('select_organization');
+    $n = ($name !== null) ? " name='{$name}'" : '';
+    $i = ($id !== null) ? " id='{$id}'" : '';
+    $organization_select = "<select$n$i>";
+
+    $selected = $current == 0 ? " selected" : "";
+    $organization_select .= "<option value='0'$selected>{$option_name}</option>";
+
+    foreach ($list_data as $row)
+      {
+        $organization_title = htmlspecialchars($row['title']);
+        $id = $row['id'];
+        $selected = $current == $id ? " selected" : "";
+        $organization_select .= "<option value='$id'$selected>{$organization_title}</option>";
+      }
+
+    $option_name = $lang->get('other');
+    if ($include_other) {
+        $selected = $current == -1 ? " selected" : "";
+        $organization_select .= "<option value='-1'$selected>{$option_name}</option>";
+    }
+    $organization_select .= "</select>";
+
+    return $organization_select;
+}
+?>
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]