Viewing File entity.php of 0.00.1a
|
1: <?php 2: /* ------------------------------------------------------------- 3: This file is part of FreeDESK 4: 5: FreeDESK is (C) Copyright 2012 David Cutting 6: 7: FreeDESK is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeDESK is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeDESK. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freedesk/ 21: -------------------------------------------------------------- */ 22: 23: /** 24: * Entity Interface - Search, Edit, Create 25: **/ 26: 27: 28: // Output buffer on and start FreeDESK then discard startup whitespace-spam 29: ob_start(); 30: include("core/FreeDESK.php"); 31: $DESK = new FreeDESK("./"); 32: $DESK->Start(); 33: ob_end_clean(); 34: 35: 36: if (!isset($_REQUEST['sid']) || !$DESK->ContextManager->Open(ContextType::User, $_REQUEST['sid'])) 37: { 38: $data=array("title"=>$DESK->Lang->Get("welcome")); 39: $DESK->Skin->IncludeFile("min_header.php",$data); 40: 41: echo "\n<noscript>\n"; 42: echo "<h1>Sorry you must have Javascript enabled to use FreeDESK analyst portal</h1>\n"; 43: echo "</noscript>\n"; 44: 45: echo "<h3>".$DESK->Lang->Get("login_invalid").":</h3>\n"; 46: 47: 48: $DESK->Skin->IncludeFile("min_footer.php"); 49: exit(); 50: } 51: 52: 53: // So we're authenticated let's view the main page 54: $data=array("title"=>"FreeDESK"); 55: $DESK->Skin->IncludeFile("min_header.php",$data); 56: 57: if (!isset($_REQUEST['mode'])) 58: $mode=""; 59: else 60: $mode=$_REQUEST['mode']; 61: if (!isset($_REQUEST['entity'])) 62: $entity=""; 63: else 64: $entity=$_REQUEST['entity']; 65: 66: $table = $DESK->DataDictionary->GetTable($entity); 67: 68: if ( ($table === false) || (!$table->editable) ) 69: { 70: echo "<h3>".$DESK->Lang->Get("entity_not_found")."</h3>"; 71: } 72: else if (!$DESK->ContextManager->Permission("entity_view.".$entity)) 73: { 74: echo "<h3>".$DESK->Lang->Get("permission_denied")."</h3>"; 75: } 76: else if ($mode == "search") 77: { 78: echo "<script type=\"text/javascript\">\n"; 79: echo "DESKSearch.entity = \"".$entity."\";\n"; 80: echo "</script>\n"; 81: echo "<div id=\"searchfields\">\n"; 82: echo "<table class=\"search\">\n"; 83: echo "<form id=\"entitysearch\" onsubmit=\"return false;\">\n"; 84: 85: $searchnow=false; 86: foreach($table->fields as $id => $field) 87: { 88: if ($field->searchable) 89: { 90: echo "<tr><td>".$field->name."</td>\n"; 91: $val=""; 92: if (isset($_REQUEST[$field->field])) 93: { 94: $val=$_REQUEST[$field->field]; 95: if ($val!="") 96: $searchnow=true; 97: } 98: echo "<td><input type=\"text\" name=\"".$field->field."\" value=\"".$val."\"></td></tr>\n"; 99: } 100: } 101: echo "<tr><td> </td>\n"; 102: echo "<td><input type=\"submit\" value=\"".$DESK->Lang->Get("search")."\" onclick=\"DESKSearch.search();\"></td>\n"; 103: echo "</tr>"; 104: echo "</form></table>\n"; 105: echo "</div>\n"; 106: 107: echo "<div id=\"searchresults\">\n"; 108: echo "</div>"; 109: 110: 111: echo "<script type=\"text/javascript\">\n"; 112: if (isset($_REQUEST['callback']) && $_REQUEST['callback']!="") 113: echo "DESKSearch.callback = window.opener.".$_REQUEST['callback'].";\n"; 114: else 115: echo "DESKSearch.callback = null;\n"; 116: if (isset($_REQUEST['onereturn']) && $_REQUEST['onereturn']==1) 117: echo "DESKSearch.callbackOnSingle = true;\n"; 118: else 119: echo "DESKSearch.callbackOnSingle = false;\n"; 120: if ($searchnow) 121: echo "DESKSearch.search();\n"; 122: echo "</script>\n"; 123: 124: } 125: else if ($mode == "edit") 126: { 127: $loaded = $DESK->EntityManager->Load($entity, $_REQUEST['value']); 128: if ($loaded !== false) 129: { 130: $data = $loaded->GetData(); 131: echo "<table class=\"edit\">\n"; 132: echo "<form id=\"entity_edit\" onsubmit=\"return false;\">\n"; 133: echo "<input type=\"hidden\" name=\"mode\" value=\"entity_save\">\n"; 134: echo "<input type=\"hidden\" name=\"entity\" value=\"".$entity."\">\n"; 135: foreach($table->fields as $id => $field) 136: { 137: echo "<tr>\n"; 138: echo "<td>".$field->name."</td>\n"; 139: echo "<td>\n"; 140: // TODO: Different field types in full 141: if ($field->type == DD_FieldType::Password) 142: $t="password"; 143: else 144: $t="text"; 145: $i="<input type=\"".$t."\" name=\"".$id."\" value=\"".$data[$id]."\""; 146: if ($field->readonly) 147: $i.=" readonly"; 148: $i.=">"; 149: echo $i; 150: echo "</td>\n"; 151: echo "</tr>\n"; 152: } 153: 154: echo "<tr><td>\n"; 155: echo "<a href=\"#\" onclick=\"window.close();\">Cancel</a>"; 156: echo "</td><td>"; 157: echo "<input type=\"submit\" value=\"".$DESK->Lang->Get("save")."\" onclick=\"DESK.formAPI('entity_edit');\"> "; 158: echo "<input type=\"submit\" value=\"".$DESK->Lang->Get("save_close")."\" onclick=\"DESK.formAPI('entity_edit',true);\">"; 159: echo "</td></tr>\n"; 160: 161: echo "</form></table>\n"; 162: } 163: else 164: { 165: echo "Entity Load Failed"; 166: } 167: } 168: else if ($mode == "create") 169: { 170: echo "<table class=\"create\">\n"; 171: echo "<form id=\"entity_create\" onsubmit=\"return false;\">\n"; 172: echo "<input type=\"hidden\" name=\"mode\" value=\"entity_create\">\n"; 173: echo "<input type=\"hidden\" name=\"entity\" value=\"".$entity."\">\n"; 174: foreach($table->fields as $id => $field) 175: { 176: echo "<tr>\n"; 177: echo "<td>".$field->name."</td>\n"; 178: echo "<td>\n"; 179: // TODO: Different field types in full 180: if ($field->type == DD_FieldType::Password) 181: $t="password"; 182: else 183: $t="text"; 184: echo "<input type=\"".$t."\" name=\"".$id."\" value=\"\">\n"; 185: echo "</td></tr>"; 186: } 187: echo "<tr><td>\n"; 188: echo "<a href=\"#\" onclick=\"window.close();\">Cancel</a>"; 189: echo "</td><td>"; 190: echo "<input type=\"submit\" value=\"".$DESK->Lang->Get("save")."\" onclick=\"DESK.formAPI('entity_create');\"> "; 191: echo "<input type=\"submit\" value=\"".$DESK->Lang->Get("save_close")."\" onclick=\"DESK.formAPI('entity_create',true);\">"; 192: echo "</td></tr>\n"; 193: 194: echo "</form></table>\n"; 195: } 196: 197: else 198: { 199: echo "<h3>".$DESK->Lang->Get("action_invalid")."</h3>"; 200: } 201: 202: 203: $DESK->Skin->IncludeFile("min_footer.php"); 204: 205: 206: ?> 207: