File: 0.00.0a/entity.php (View as Code)

1: 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\n"; 44: 45: echo "

".$DESK->Lang->Get("login_invalid").":

\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 "

".$DESK->Lang->Get("entity_not_found")."

";
71: } 72: else if (!$DESK->ContextManager->Permission("entity_view.".$entity)) 73: { 74: echo "

".$DESK->Lang->Get("permission_denied")."

";
75: } 76: else if ($mode == "search") 77: { 78: echo "\n"; 81: echo "
\n"; 82: echo "\n"; 83: echo "
\n";
84: 85: $searchnow=false; 86: foreach($table->fields as $id => $field) 87: { 88: if ($field->searchable) 89: { 90: echo "\n"; 91: $val=""; 92: if (isset($_REQUEST[$field->field])) 93: { 94: $val=$_REQUEST[$field->field]; 95: if ($val!="") 96: $searchnow=true; 97: } 98: echo "\n"; 99: } 100: } 101: echo "\n"; 102: echo "\n"; 103: echo ""; 104: echo "
".$field->name."field."\" value=\"".$val."\">
 Lang->Get("search")."\" onclick=\"DESKSearch.search();\">
\n";
105: echo "
\n";
106: 107: echo "
\n"; 108: echo "
";
109: 110: 111: echo "\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 "\n"; 132: echo "
\n";
133: echo "\n"; 134: echo "\n"; 135: foreach($table->fields as $id => $field) 136: { 137: echo "\n"; 138: echo "\n"; 139: echo "\n"; 147: echo "\n"; 148: } 149: 150: echo "\n"; 156: 157: echo "
".$field->name."\n"; 140: // TODO: Different field types 141: $i="142: if ($field->readonly) 143: $i.=" readonly"; 144: $i.=">"; 145: echo $i; 146: echo "
\n"; 151: echo "Cancel"; 152: echo ""; 153: echo "Lang->Get("save")."\" onclick=\"DESK.formAPI('entity_edit');\"> "; 154: echo "Lang->Get("save_close")."\" onclick=\"DESK.formAPI('entity_edit',true);\">"; 155: echo "
\n";
158: } 159: else 160: { 161: echo "Entity Load Failed"; 162: } 163: } 164: else if ($mode == "create") 165: { 166: echo "\n"; 167: echo "
\n";
168: echo "\n"; 169: echo "\n"; 170: foreach($table->fields as $id => $field) 171: { 172: echo "\n"; 173: echo "\n"; 174: echo ""; 178: } 179: echo "\n"; 185: 186: echo "
".$field->name."\n"; 175: // TODO: Different field types 176: echo "\n"; 177: echo "
\n"; 180: echo "Cancel"; 181: echo ""; 182: echo "Lang->Get("save")."\" onclick=\"DESK.formAPI('entity_create');\"> "; 183: echo "Lang->Get("save_close")."\" onclick=\"DESK.formAPI('entity_create',true);\">"; 184: echo "
\n";
187: } 188: 189: else 190: { 191: echo "

".$DESK->Lang->Get("action_invalid")."

";
192: } 193: 194: 195: $DESK->Skin->IncludeFile("min_footer.php"); 196: 197: 198: ?> 199: