[1] | 1 | #!/usr/local/bin/php -q |
---|
| 2 | <?php |
---|
| 3 | /** |
---|
| 4 | * list_template.cli.php |
---|
| 5 | * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | $CFG->enable_session = false; |
---|
| 10 | $CFG->log_screen_priority = LOG_DEBUG; |
---|
| 11 | error_reporting(E_ALL); |
---|
| 12 | require_once dirname(__FILE__) . '/../../config/boot.inc.php'; |
---|
| 13 | |
---|
| 14 | $op = null; |
---|
| 15 | $valid_ops = array('headerrows', 'listrows'); |
---|
| 16 | |
---|
| 17 | // Test arguments. |
---|
| 18 | if ($_SERVER['argc'] == 2) { |
---|
| 19 | $db_tbl = $_SERVER['argv'][1]; |
---|
| 20 | } else if ($_SERVER['argc'] == 3) { |
---|
| 21 | $db_tbl = $_SERVER['argv'][1]; |
---|
| 22 | $op = $_SERVER['argv'][2]; |
---|
| 23 | } else { |
---|
| 24 | die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the first argument.\n"); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | // Get DB tables. |
---|
| 28 | $qid = dbQuery("SHOW TABLES"); |
---|
| 29 | while (list($row) = mysql_fetch_row($qid)) { |
---|
| 30 | $tables[] = $row; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | // Make sure requested table is in database. |
---|
| 34 | if (!in_array($db_tbl, $tables)) { |
---|
| 35 | die(basename($_SERVER['argv'][0]) . " Warning: $db_tbl does not exist in database $CFG->database. Please select one of: \n\n" . join("\n", $tables) . "\n\n"); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | // Make sure op is valid. |
---|
| 39 | if (isset($op) && !in_array($op, $valid_ops)) { |
---|
| 40 | die(basename($_SERVER['argv'][0]) . " Warning: Operation '$op' is not something I know how to do Please select one of: " . join(", ", $valid_ops) . "\n"); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | // Get DB table column info. |
---|
| 44 | $qid = dbQuery("DESCRIBE " . addslashes($db_tbl)); |
---|
| 45 | while ($row = mysql_fetch_row($qid)) { |
---|
| 46 | $cols[] = $row; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | // Loop through columns |
---|
| 50 | if (is_array($cols) && !empty($cols)) { |
---|
| 51 | foreach ($cols as $col) { |
---|
| 52 | |
---|
| 53 | // Human readable. |
---|
| 54 | $field = $col[0]; |
---|
| 55 | $title = ucfirst(str_replace('_', ' ', $field)); |
---|
| 56 | $type = preg_replace('/^(\w+).*$/', '\\1', $col[1]); |
---|
| 57 | |
---|
| 58 | // Get primary key. |
---|
| 59 | if ('PRI' == $col[3]) { |
---|
| 60 | $primary_key = $field; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | // Column headers. |
---|
| 64 | $headers[$field] = $title; |
---|
| 65 | |
---|
| 66 | // Column data. |
---|
| 67 | if (preg_match("/enum\('true'\)/", $col[1])) { |
---|
| 68 | $listrows[] = "<\x3fphp echo (!empty(\$list[\$i]['$field'])) ? '•' : ''; \x3f>"; |
---|
| 69 | } else if ( |
---|
| 70 | 'tinytext' == $type || |
---|
| 71 | 'text' == $type || |
---|
| 72 | 'mediumtext' == $type || |
---|
| 73 | 'longtext' == $type || |
---|
| 74 | 'tinyblob' == $type || |
---|
| 75 | 'blob' == $type || |
---|
| 76 | 'mediumblob' == $type || |
---|
| 77 | 'longblob' == $type |
---|
| 78 | ) { |
---|
| 79 | $listrows[] = "<\x3fphp echo strlen(\$list[\$i]['$field'])<50 \x3f oTxt(\$list[\$i]['$field'], true) : oTxt(trim(substr(\$list[\$i]['$field'], 0, 50)) . '...'); \x3f>"; |
---|
| 80 | } else if (preg_match('/.*(begin|start).*date.*/i', $field)) { |
---|
| 81 | $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date($CFG->date_format, strtotime(\$list[\$i]['$field'])); \x3f>"; |
---|
| 82 | } else if (preg_match('/.*(end|expire).*date.*/i', $field)) { |
---|
| 83 | $listrows[] = "<\x3fphp echo '9999-12-31' == \$list[\$i]['$field'] ? '' : date($CFG->date_format, strtotime(\$list[\$i]['$field'])); \x3f>"; |
---|
| 84 | } else if (preg_match('/datetime/i', $type)) { |
---|
| 85 | $listrows[] = "<\x3fphp echo '0000-00-00 00:00:00' == \$list[\$i]['$field'] ? '' : date($CFG->date_format, strtotime(\$list[\$i]['$field'])); \x3f>"; |
---|
| 86 | } else if (preg_match('/date/i', $type)) { |
---|
| 87 | $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date($CFG->date_format, strtotime(\$list[\$i]['$field'])); \x3f>"; |
---|
| 88 | } else if (preg_match('/(amount|_rate)/i', $field)) { |
---|
| 89 | $listrows[] = "<\x3fphp printf('$%01.2f', \$list[\$i]['$field']); \x3f>"; |
---|
| 90 | } else if (preg_match('/(added_by_admin_id)/i', $field)) { |
---|
| 91 | $listrows[] = "<\x3fphp echo oTxt(\$list[\$i]['added_admin_username']); \x3f>"; |
---|
| 92 | } else if (preg_match('/(modified_by_admin_id)/i', $field)) { |
---|
| 93 | $listrows[] = "<\x3fphp echo oTxt(\$list[\$i]['modified_admin_username']); \x3f>"; |
---|
| 94 | } else if ('rank' == $field) { |
---|
| 95 | $listrows[] = "<input type=\"text\" name=\"rank[<\x3fphp echo \$list[\$i]['$primary_key']; \x3f>]\" value=\"<\x3fphp echo \$list[\$i]['rank']; \x3f>\" size=\"5\" />"; |
---|
| 96 | } else { |
---|
| 97 | $listrows[] = "<\x3fphp echo oTxt(\$list[\$i]['$field'], true); \x3f>"; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | } else { |
---|
| 101 | die(basename($_SERVER['argv'][0]) . " Warning: $db_tbl does not have any columns.\n"); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | // Print the template out. |
---|
| 105 | echo isset($op) ? '' : <<<E_O_F |
---|
| 106 | |
---|
| 107 | <\x3fphp include 'form_error_header.ihtml'; \x3f> |
---|
| 108 | <form action="<\x3fphp echo \$_SERVER['PHP_SELF']; \x3f>" method="post"> |
---|
| 109 | <\x3fphp printHiddenSession(false); \x3f> |
---|
| 110 | |
---|
| 111 | <div id="commandbox"> |
---|
| 112 | <span class="nowrap commandtext"><a href="<\x3fphp echo ohref(\$_SERVER['PHP_SELF'] . '?op=add'); \x3f>"><\x3fphp echo _("Add <##>"); \x3f></a></span> |
---|
| 113 | <br /> |
---|
| 114 | |
---|
| 115 | <input type="text" class="forminputtext" size="20" name="search_query" value="<\x3fphp echo getFormData('search_query'); \x3f>" title="<\x3fphp echo oTxt(_("Fields searched: <##>.")); \x3f>" /> |
---|
| 116 | <select name="filter_<##>"> |
---|
| 117 | <\x3fphp // printSelectForm('<##>_tbl', "CONCAT(<##>_id, '—', city, '—', title)", '<##>_id', getFormData('filter_<##>'), array('Any <##>'), 'ORDER BY <##> ASC'); \x3f> |
---|
| 118 | </select> |
---|
| 119 | <input type="submit" name="list" value="<\x3fphp echo _("Search"); \x3f>" /> |
---|
| 120 | </div> |
---|
| 121 | |
---|
[30] | 122 | <?php include 'adm_list_info.ihtml'; \x3f> |
---|
[1] | 123 | |
---|
| 124 | <table class="list"> |
---|
| 125 | <tr> |
---|
| 126 | <th> </th> |
---|
| 127 | <th> </th> |
---|
| 128 | |
---|
| 129 | E_O_F; |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | // Print header rows. |
---|
| 133 | if (!isset($op) || 'headerrows' == $op) { |
---|
| 134 | foreach ($headers as $field=>$title) { |
---|
| 135 | if ($field == $primary_key) { |
---|
| 136 | echo " <th><\x3fphp echo \$so->printSortHeader('$db_tbl.$field', _(\"ID\"), 'ASC'); \x3f></th>\n"; |
---|
| 137 | } else { |
---|
| 138 | echo " <th><\x3fphp echo \$so->printSortHeader('$db_tbl.$field', _(\"$title\"), 'ASC'); \x3f></th>\n"; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | echo isset($op) ? '' : <<<E_O_F |
---|
| 144 | <th> </th> |
---|
| 145 | </tr> |
---|
| 146 | <\x3fphp for (\$i = 0; \$i <= \$page->last_item - \$page->first_item && \$page->total_items > 0; \$i++) { \x3f> |
---|
| 147 | <tr> |
---|
| 148 | <td class="nowrap"><a title="<\x3fphp printf(_("Edit %s"), oTxt(\$list[\$i]['______RECORD_NAME______'])) \x3f>" href="<\x3fphp echo ohref(\$_SERVER['PHP_SELF'] . '?op=edit&$primary_key=' . \$list[\$i]['$primary_key']); \x3f>"><img src="<\x3fphp echo \$CFG->admin_url; \x3f>/_widgets/edit.gif" alt="Edit" width="14" height="18" border="0"></a> </td> |
---|
| 149 | <td class="nowrap"><a title="<\x3fphp printf(_("Versions of %s"), oTxt(\$list[\$i]['______RECORD_NAME______'])) \x3f>" href="<\x3fphp echo ohref("\$CFG->admin_url/record_versions.php?record_table=$db_tbl&record_key=$primary_key&boomerang=true&record_val=" . \$list[\$i]['$primary_key']); \x3f>"><img src="<\x3fphp echo \$CFG->admin_url; \x3f>/_widgets/subcategory.gif" alt="" width="18" height="14" border="0" /></a> </td> |
---|
| 150 | |
---|
| 151 | E_O_F; |
---|
| 152 | |
---|
| 153 | // Print List rows. |
---|
| 154 | if (!isset($op) || 'listrows' == $op) { |
---|
| 155 | foreach ($listrows as $col_data) { |
---|
| 156 | ?> |
---|
| 157 | <td class="nowrap"><?php echo $col_data; ?> </td> |
---|
| 158 | <?php |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | echo isset($op) ? '' : <<<E_O_F |
---|
| 163 | <td class="nowrap" align="right"><a title="<\x3fphp printf(_("Delete %s"), oTxt(\$list[\$i]['______RECORD_NAME______'])) \x3f>" href="<\x3fphp echo ohref(\$_SERVER['PHP_SELF'] . "?op=del&$primary_key=" . \$list[\$i]['$primary_key']); \x3f>" onClick="javascript:return confirm('<\x3fphp printf(_("Are you sure you want to delete the record %s? This action is permanent and cannot be undone."), oTxt(\$list[\$i]['______RECORD_NAME______'])) \x3f>')"><img src="<\x3fphp echo \$CFG->admin_url; \x3f>/_widgets/delete.gif" alt="Delete" width="16" height="17" border="0"></a> </td> |
---|
| 164 | </tr> |
---|
| 165 | <\x3fphp } \x3f> |
---|
| 166 | </table> |
---|
| 167 | |
---|
| 168 | <\x3fphp if (\$page->total_pages > 1) { \x3f> |
---|
| 169 | <div class="nowrap commandtext" style="float: right;"><\x3fphp echo _("Pages:"); \x3f> <\x3fphp \$page->printPageNumbers() \x3f></div> |
---|
| 170 | <\x3fphp } \x3f> |
---|
| 171 | </form> |
---|
| 172 | |
---|
| 173 | E_O_F; |
---|
| 174 | |
---|
| 175 | ?> |
---|