ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Registry.php
Go to the documentation of this file.
1 <?php
2 
10 
11 
12  protected function getStandardField($request, &$entry, $key) {
13  if (array_key_exists('field_' . $key, $request)) {
14  $entry[$key] = $request['field_' . $key];
15  } else {
16  if (isset($entry[$key])) unset($entry[$key]);
17  }
18  }
19 
20  public function formToMeta($request, $entry = array(), $override = NULL) {
21  $this->getStandardField($request, $entry, 'name');
22  $this->getStandardField($request, $entry, 'description');
23  $this->getStandardField($request, $entry, 'key');
24  $this->getStandardField($request, $entry, 'secret');
25  $this->getStandardField($request, $entry, 'RSAcertificate');
26  $this->getStandardField($request, $entry, 'callback_url');
27 
28  if ($override) {
29  foreach($override AS $key => $value) {
30  $entry[$key] = $value;
31  }
32  }
33 
34  return $entry;
35  }
36 
37  protected function requireStandardField($request, $key) {
38  if (!array_key_exists('field_' . $key, $request))
39  throw new Exception('Required field [' . $key . '] was missing.');
40  if (empty($request['field_' . $key]))
41  throw new Exception('Required field [' . $key . '] was empty.');
42  }
43 
44  public function checkForm($request) {
45  $this->requireStandardField($request, 'name');
46  $this->requireStandardField($request, 'description');
47  $this->requireStandardField($request, 'key');
48  }
49 
50 
51  protected function header($name) {
52  return '<tr ><td>&nbsp;</td><td class="header">' . $name . '</td></tr>';
53 
54  }
55 
56  protected function readonlyDateField($metadata, $key, $name) {
57  $value = '<span style="color: #aaa">Not set</a>';
58  if (array_key_exists($key, $metadata))
59  $value = date('j. F Y, G:i', $metadata[$key]);
60  return '<tr>
61  <td class="name">' . $name . '</td>
62  <td class="data">' . $value . '</td></tr>';
63 
64  }
65 
66  protected function readonlyField($metadata, $key, $name) {
67  $value = '';
68  if (array_key_exists($key, $metadata))
69  $value = $metadata[$key];
70  return '<tr>
71  <td class="name">' . $name . '</td>
72  <td class="data">' . htmlspecialchars($value) . '</td></tr>';
73 
74  }
75 
76  protected function hiddenField($key, $value) {
77  return '<input type="hidden" name="' . $key . '" value="' . htmlspecialchars($value) . '" />';
78  }
79 
80  protected function flattenLanguageField(&$metadata, $key) {
81  if (array_key_exists($key, $metadata)) {
82  if (is_array($metadata[$key])) {
83  if (isset($metadata[$key]['en'])) {
84  $metadata[$key] = $metadata[$key]['en'];
85  } else {
86  unset($metadata[$key]);
87  }
88  }
89  }
90  }
91 
92  protected function standardField($metadata, $key, $name, $textarea = FALSE) {
93  $value = '';
94  if (array_key_exists($key, $metadata)) {
95  $value = htmlspecialchars($metadata[$key]);
96  }
97 
98  if ($textarea) {
99  return '<tr><td class="name">' . $name . '</td><td class="data">
100  <textarea name="field_' . $key . '" rows="5" cols="50">' . $value . '</textarea></td></tr>';
101 
102  } else {
103  return '<tr><td class="name">' . $name . '</td><td class="data">
104  <input type="text" size="60" name="field_' . $key . '" value="' . $value . '" /></td></tr>';
105 
106  }
107  }
108 
109  public function metaToForm($metadata) {
110  return '<form action="registry.edit.php" method="post">' .
111  '<div id="tabdiv">' .
112  '<ul>' .
113  '<li><a href="#basic">Name and descrition</a></li>' .
114  '</ul>' .
115  '<div id="basic"><table class="formtable">' .
116  $this->standardField($metadata, 'name', 'Name of client') .
117  $this->standardField($metadata, 'description', 'Description of client', TRUE) .
118  $this->readonlyField($metadata, 'owner', 'Owner') .
119  $this->standardField($metadata, 'key', 'Consumer Key') .
120  $this->readonlyField($metadata, 'secret', 'Consumer Secret<br/>(Used for HMAC_SHA1 signatures)') .
121  $this->standardField($metadata, 'RSAcertificate', 'RSA certificate (PEM)<br/>(Used for RSA_SHA1 signatures)', TRUE) .
122  $this->standardField($metadata, 'callback_url', 'Static/enforcing callback-url') .
123  $this->hiddenField('field_secret', $metadata['secret']) .
124 
125  '</table></div>' .
126  '</div>' .
127  '<input type="submit" name="submit" value="Save" style="margin-top: 5px" />' .
128  '</form>';
129  }
130 
131 }
132 
133 
checkForm($request)
Definition: Registry.php:44
foreach($paths as $path) $request
Definition: asyncclient.php:32
metaToForm($metadata)
Definition: Registry.php:109
$metadata['__DYNAMIC:1__']
getStandardField($request, &$entry, $key)
Definition: Registry.php:12
requireStandardField($request, $key)
Definition: Registry.php:37
standardField($metadata, $key, $name, $textarea=FALSE)
Definition: Registry.php:92
hiddenField($key, $value)
Definition: Registry.php:76
readonlyField($metadata, $key, $name)
Definition: Registry.php:66
readonlyDateField($metadata, $key, $name)
Definition: Registry.php:56
formToMeta($request, $entry=array(), $override=NULL)
Definition: Registry.php:20
$key
Definition: croninfo.php:18
flattenLanguageField(&$metadata, $key)
Definition: Registry.php:80