function SLAM_makeSearchBoxHTML($config, $db, $user, $request, $result) { /* generates the field search box */ /* register the necessary header files */ $config->html['css'][] = 'css/search.css'; $config->html['js'][] = 'js/search.js'; $s = "<form name='searchForm' action='{$config->html['url']}' method='POST'>\n"; $s .= SLAM_makeHiddenInput($request->location, 'loc'); $categories = array_keys($request->categories); foreach ($categories as $category) { $s .= SLAM_makeHiddenInput($category, 'cat[]'); } $s .= "<div id='searchContainer'>\n"; /* default search action is to search all fields */ if (empty($request->search)) { $search = array(0 => array('field' => '(Search all)', 'value' => '', 'mode' => 'LIKE', 'join' => '')); } else { foreach ($request->search['field'] as $i => $field) { $search[$i] = array('field' => $field, 'value' => $request->search['value'][$i], 'mode' => $request->search['mode'][$i], 'join' => $request->search['join'][$i]); } } /* all the possible fields to search in */ $fields = array(); foreach ($result->fields as $category => $structure) { if (empty($fields)) { $fields = array_keys($structure); } else { $fields = array_intersect($fields, array_keys($structure)); } } $diff = array_intersect($fields, $config->values['hide_fields']); if (!$user->superuser) { $fields = array_diff($fields, $diff); } /* prepend the "search all fields" option to the list of searchable fields */ array_unshift($fields, '(Search all)'); /* the possible search modes */ $modes = array('~' => 'LIKE', '!~' => 'NOT LIKE', '>' => '>', '=' => '=', '<' => '<'); /* the possible search joiners */ $joins = array('' => '', 'AND' => 'AND', 'OR' => 'OR'); $s .= "<div id='searchTerms'>\n"; $i = 0; foreach ($search as $terms) { $s .= "<div id='search_group_{$i}' class='searchClass'>\n"; $s .= SLAM_makeMenuHTML($terms['field'], @array_combine($fields, $fields), "name='s_field[]' id='search_field_{$i}'", false); $s .= SLAM_makeMenuHTML($terms['mode'], $modes, "name='s_mode[]' id='search_mode_{$i}'", false); $s .= SLAM_makeInputHTML($terms['value'], 16, 255, "name='s_value[]' id='search_value_{$i}'"); $s .= " " . SLAM_makeMenuHTML($terms['join'], $joins, "name='s_join[]' id='search_join_{$i}' onChange='doSearchGroup({$i},this.options[this.selectedIndex].value); return false;'"); /* the last field should have a plus sign so as to be able to add more terms */ $c = $i == count($search) - 1 ? '+' : '-'; $f = $i == count($search) - 1 ? "addSearchGroup({$i})" : "removeSearchGroup({$i})"; $s .= "<input type='button' class='searchClassButton' id='search_toggle_{$i}' onClick=\"{$f}; return false;\" value='{$c}' />\n"; $s .= "</div>\n"; $i++; } $s .= "</div>\n"; $s .= "<input type='submit' name='action' value='Search' />\n"; $s .= "</div>\n"; $s .= "</form>\n"; return $s; }
function SLAM_makeAssetEditHTML(&$config, $db, $user, $request, &$result) { /* Displays the edit page for the records corresponding to the first category in $result */ /* register the necessary header files */ $config->html['css'][] = 'css/asset.css'; $config->html['js'][] = 'js/asset.js'; $config->html['js'][] = 'js/convert.js'; /* register the javascript plugin stub */ $config->html['onload'][] = 'doEditJS()'; $s = "<form id='editRecord' action='{$config->html['url']}' method='POST'>\n"; $category = array_shift(array_keys($request->categories)); //the first category $assets = $result->assets[$category]; $structure = $result->fields[$category]; $editable = array(); /* retrieve the field values, either for a new entry or for editing existing ones */ if ($request->action == 'new') { $editable[] = true; $fields = SLAM_setAssetFields($config, $db, $user, $category, $structure, null); /* save the identifier to the form so we can come back to it if the user saves changes */ $s .= SLAM_makeHiddenInput($fields['Identifier'], 'Identifier'); $s .= SLAM_makeHiddenInput('true', 'new'); } elseif ($request->action == 'clone') { $editable[] = true; $fields = SLAM_setAssetFields($config, $db, $user, $category, $structure, $assets[0]); /* save the identifier to the form so we can come back to it if the user saves changes */ $s .= SLAM_makeHiddenInput($fields['Identifier'], 'Identifier'); $s .= SLAM_makeHiddenInput('true', 'new'); } elseif (count($assets) > 0) { /* retrieve the consensus field values */ $fields = SLAM_getAssetFields($config, $db, $user, $assets); foreach ($assets as $asset) { /* save the editable status for every asset */ $editable[] = SLAM_getAssetAccess($user, $asset) > 1; /* save all of the identifiers we're to update into the form */ $s .= SLAM_makeHiddenInput($asset['Identifier'], 'Identifier[]'); } $editable = array_unique($editable); /* fields that cannot be edited for more than one asset at a time shouldn't be shown */ if (count($assets) > 1) { unset($structure['Files']); } } else { return SLAM_makeNoteHTML("This asset has been removed, or does not exist.", true); } /* if there are a mix of editable and uneditable assets, provide the user a warning */ if (count($editable) > 1) { $config->html['onload'][] = 'doNonEditableWarning()'; $editable = true; } else { $editable = $editable[0]; } /* set our location */ $s .= SLAM_makeHiddenInput($request->location, 'loc'); $s .= SLAM_makeHiddenInput($category, 'cat'); $s .= "<div id='assetEditContainer'>\n"; $export = http_build_query(array_merge($_GET, $_POST)); $f = <<<EOL <div id='assetEditFunctions'> jump to <a href='#End'>bottom</a> | <a href='#' onClick="setSwitchableTR('none'); return false">hide</a>/<a href='' onClick="setSwitchableTR(''); return false">show</a> unused | <a href='ext/export.php?{$export}'>export</a>/<a href='ext/print.php?{$export}'>print</a> | <a href='#' onClick="showPopupDiv('pub/help_edit.html','helpDiv',{}); return false">help</a> </div> EOL; $b = "{$f}<table id='assetEdit'>\n"; /* go through the structure and put together each fields's html */ foreach ($structure as $name => $scheme) { /* when we run across the title field, save it to the $t variable for later use */ if ($name == $config->categories[$category]['title_field']) { $t = "<div id='assetEditTitle'>{$category} : {$fields[$name]}</div>\n"; } /* collapse fields that are empty */ $collapsed = false; if (in_array($fields[$name], $config->values['hide_empty'])) { $collapsed = true; } if ($request->action == 'new') { $collapsed = false; } switch ($name) { case 'Identifier': /* identifier should not be editable if the user is not a superuser */ $b .= SLAM_makeFieldHTML($config, $request, $fields[$name], $scheme, $user->superuser, $collapsed); break; case 'permissions': /* insert the permissions control panel */ $b .= SLAM_makePermissionsHTML($config, $user, $assets); $b .= SLAM_makeHiddenInput(base64_encode(json_encode($fields[$name])), 'permissions'); break; case 'Project': /* save the default projects array to the structure of the projects field */ $scheme['values'] = $config->projects; $b .= SLAM_makeFieldHTML($config, $request, $fields[$name], $scheme, $editable, False); break; case 'Files': /* if there's a "Files" field, show a link to the file browser instead */ $b .= "<tr>\n<td class='assetEditField'>Files :</td><td class='assetEditValue'><input type='button' class='assetFileButton' onClick=\"showFileManager('ext/files.php?i={$fields['Identifier']}'); return false\" value='Open Browser' /></td><td class='assetEditFunction'> </td>\n</tr>\n"; break; default: if ($scheme['hidden'] && !$user->superuser) { $b .= SLAM_makeHiddenInput($fields[$name], 'edit_' . base64_encode($scheme['name'])); } else { $b .= SLAM_makeFieldHTML($config, $request, $fields[$name], $scheme, $editable, $collapsed); } } } $s .= "{$t}{$b}</table>\n"; $s .= "<div id='assetEditActions'>\n"; if ($editable) { $s .= "<input type='button' name='action' value='Cancel' onClick='javascript: history.go(-1)'/><input type='submit' name='action' value='Delete' onClick=\"javascript:return confirm('Are you sure you want to delete the selected record?')\"/><input type='submit' name='action' value='Save' /><input type='submit' name='action' value='Save Changes' />\n"; } else { $s .= "<input type='button' name='action' value='Cancel' onClick='javascript: history.go(-1)'/>\n"; } $s .= "<a name='End'> </a>\n"; $s .= "</div>\n</div></form>\n"; return $s; }