File: 0.01.1a/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_".$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"; 151: echo "\n"; 152: } 153: 154: echo "\n"; 160: 161: echo "
".$field->name."\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="146: if ($field->readonly) 147: $i.=" readonly"; 148: $i.=">"; 149: echo $i; 150: echo "
\n"; 155: echo "Cancel"; 156: echo ""; 157: echo "Lang->Get("save")."\" onclick=\"DESK.formAPI('entity_edit');\"> "; 158: echo "Lang->Get("save_close")."\" onclick=\"DESK.formAPI('entity_edit',true);\">"; 159: echo "
\n";
162: } 163: else 164: { 165: echo "Entity Load Failed"; 166: } 167: } 168: else if ($mode == "create") 169: { 170: echo "\n"; 171: echo "
\n";
172: echo "\n"; 173: echo "\n"; 174: foreach($table->fields as $id => $field) 175: { 176: echo "\n"; 177: echo "\n"; 178: echo ""; 186: } 187: echo "\n"; 193: 194: echo "
".$field->name."\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 "\n"; 185: echo "
\n"; 188: echo "Cancel"; 189: echo ""; 190: echo "Lang->Get("save")."\" onclick=\"DESK.formAPI('entity_create');\"> "; 191: echo "Lang->Get("save_close")."\" onclick=\"DESK.formAPI('entity_create',true);\">"; 192: echo "
\n";
195: } 196: 197: else 198: { 199: echo "

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

";
200: } 201: 202: 203: $DESK->Skin->IncludeFile("min_footer.php"); 204: 205: 206: ?> 207: