13 define(
"TITLE_ADMIN_OBLIGATION_FILE", _(
"Obligations and Risks Administration"));
21 private $obligationMap;
25 $this->Name =
"admin_obligation";
26 $this->Title = TITLE_ADMIN_OBLIGATION_FILE;
27 $this->MenuList =
"Admin::Obligation Admin";
29 parent::__construct();
31 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
32 $this->obligationMap = $GLOBALS[
'container']->get(
'businessrules.obligationmap');
38 $topicarray =
DB2ValArray(
"obligation_ref",
"ob_topic",
true,
" order by ob_topic");
45 $sql =
"SELECT count(*) from obligation_ref where ob_pk <> $1 and (ob_topic <> '' and ob_topic = $2) and (ob_text <> '' and ob_text = $3)";
46 $check_count = $this->
dbManager->getSingleRow($sql,array($obId,$topic,$text));
47 return (0 < $check_count[
'count']);
55 if ($this->
State != PLUGIN_STATE_READY) {
59 $URL = $this->Name.
"&add=y";
60 $text = _(
"Add new obligation");
61 menu_insert(
"Main::".$this->MenuList.
"::Add Obligation",0, $URL, $text);
63 $text = _(
"Select obligation");
64 menu_insert(
"Main::".$this->MenuList.
"::Select Obligation",0, $URL, $text);
70 $errorstr =
"Obligation or risk not added";
74 if (@$_POST[
"del"] ==
'y') {
77 $V .=
"<p>Obligation has not been deleted.</p>";
84 if (@$_POST[
"updateit"]) {
85 $resultstr = $this->
Updatedb($_POST);
87 if (strstr($resultstr, $errorstr)) {
95 if (@$_REQUEST[
'add'] ==
'y') {
101 if (@$_POST[
"addit"]) {
102 $resultstr = $this->
Adddb($_POST);
104 if (strstr($resultstr, $errorstr)) {
113 $ob_pk = @$_REQUEST[
'ob_pk'];
120 if (@$_POST[
'req_topic']) {
133 $V =
"<FORM name='Inputfm' action='?mod=" . $this->Name .
"' method='POST'>";
134 $V.= _(
"From which topic do you wish to view the obligations and risks:<br>");
139 $V.= _(
"From topic: ");
141 $Topicarray = array(
"All"=>
"All") + $Topicarray;
142 $Selected = @$_REQUEST[
'req_topic'];
143 $Pulldown =
Array2SingleSelect($Topicarray,
"req_topic", $Selected,
false,
false,
"",
false);
145 $V.=
" ";
147 $V.=
"<INPUT type='submit' value='$text'>\n";
169 if ($topic ==
"All") {
172 $where =
"WHERE ob_topic='". pg_escape_string($topic) .
"' ";
175 $sql =
"SELECT * FROM ONLY obligation_ref $where ORDER BY ob_pk";
180 if (pg_num_rows($result) == 0) {
181 $topic = addslashes($topic);
182 $text1 = _(
"No obligation matching the topic");
183 $text2 = _(
"were found");
184 $ob .=
"<br>$text1 '$topic' $text2.<br>";
185 pg_free_result($result);
189 $plural = (pg_num_rows($result) == 1) ?
"" :
"s";
190 $ob .= pg_num_rows($result) .
" obligation$plural found.";
192 $ob .=
"<table style='border: thin dotted gray'>";
193 $ob .=
"<table rules='rows' cellpadding='3'>";
196 $ob .=
"<th>$text</th>";
198 $ob .=
"<th>$text</th>";
200 $ob .=
"<th>$text</th>";
202 $ob .=
"<th>$text</th>";
203 $text = _(
"Classification");
204 $ob .=
"<th>$text</th>";
205 $text = _(
"Apply on modified code");
206 $ob .=
"<th>$text</th>";
207 $text = _(
"Comment");
208 $ob .=
"<th>$text</th>";
209 $text = _(
"Associated licenses");
210 $ob .=
"<th>$text</th>";
211 $text = _(
"Associated candidate licenses");
212 $ob .=
"<th>$text</th>";
215 while ($row = pg_fetch_assoc($result)) {
216 if ($lineno ++ % 2) {
217 $style =
"style='background-color:lavender'";
221 $ob .=
"<tr $style>";
223 $associatedLicenses = $this->obligationMap->getLicenseList($row[
'ob_pk']);
224 $candidateLicenses = $this->obligationMap->getLicenseList($row[
'ob_pk'],True);
227 $ob .=
"<td align=center><a href='";
229 $ob .=
"?mod=" . $this->Name .
230 "&ob_pk=$row[ob_pk]' >".
231 "<img border=0 src='" .
Traceback_uri() .
"images/button_edit.png'></a></td>";
233 $ob .=
"<td align=left>$row[ob_type]</td>";
234 $ob .=
"<td align=left>" . htmlspecialchars($row[
"ob_topic"]) .
"</td>";
235 $vetext = htmlspecialchars($row[
'ob_text']);
236 $ob .=
"<td><textarea readonly=readonly rows=3 cols=40>$vetext</textarea></td> ";
237 $ob .=
"<td align=left>$row[ob_classification]</td>";
238 $ob .=
"<td align=center>$row[ob_modifications]</td>";
239 $vetext = htmlspecialchars($row[
'ob_comment']);
240 $ob .=
"<td><textarea readonly=readonly rows=3 cols=40>$vetext</textarea></td> ";
241 $ob .=
"<td align=center>$associatedLicenses</td>";
242 $ob .=
"<td align=center>$candidateLicenses</td>";
245 pg_free_result($result);
261 if (0 < count($_POST)) {
262 $ob_pk_update = $_POST[
'ob_pk'];
263 if (! empty($ob_pk)) {
264 $ob_pk_update = $ob_pk;
265 }
else if (empty($ob_pk_update)) {
266 $ob_pk_update = $_GET[
'ob_pk'];
269 $vars[
'actionUri'] =
"?mod=" . $this->Name .
"&ob_pk=$ob_pk_update";
273 "SELECT * FROM ONLY obligation_ref WHERE ob_pk=$1", array(
275 ), __METHOD__ .
'.forUpdate');
276 if ($row ===
false) {
277 $text = _(
"No obligation matching this key");
278 $text1 = _(
"was found");
279 return "$text ($ob_pk) $text1.";
282 $associatedLicenses = $this->obligationMap->getLicenseList($ob_pk);
283 $vars[
'licnames'] = explode(
";", $associatedLicenses);
284 $candidateLicenses = $this->obligationMap->getLicenseList($ob_pk, True);
285 $vars[
'candidatenames'] = explode(
";", $candidateLicenses);
287 $row = array(
'ob_active' =>
't',
288 'ob_modifications' =>
'No',
289 'ob_text_updatable' =>
't'
293 foreach (array_keys($row) as $key) {
294 if (array_key_exists($key, $_POST)) {
295 $row[$key] = $_POST[$key];
299 $vars[
'boolYesNoMap'] = array(
"true"=>
"Yes",
"false"=>
"No");
300 $vars[
'YesNoMap'] = array(
"Yes"=>
"Yes",
"No"=>
"No");
301 $row[
'ob_active'] = $this->
dbManager->booleanFromDb($row[
'ob_active'])?
'true':
'false';
302 $row[
'ob_text_updatable'] = $this->
dbManager->booleanFromDb($row[
'ob_text_updatable'])?
'true':
'false';
303 $vars[
'isReadOnly'] = !(empty($ob_pk) || $row[
'ob_text_updatable']==
'true');
305 $vars[
'obId'] = $ob_pk?:$ob_pk_update;
308 $vars[
'licenseShortnames'] = $this->obligationMap->getAvailableShortnames();
309 natcasesort($vars[
'licenseShortnames']);
312 $vars[
'candidateShortnames'] = $this->obligationMap->getAvailableShortnames(
true);
313 natcasesort($vars[
'candidateShortnames']);
319 $vars[
'obligationClassification'] = array(
"green"=>
"green",
"white"=>
"white",
"yellow"=>
"yellow",
"red"=>
"red");
320 $vars[
'obligationTypes'] = array(
"Obligation"=>
"Obligation",
321 "Restriction"=>
"Restriction",
"Risk"=>
"Risk",
"Right"=>
"Right");
323 $vars[
'ob_type'] = empty($row[
'ob_type']) ?
'Obligation' : $row[
'ob_type'];
324 $vars[
'ob_classification'] = empty($row[
'ob_classification']) ?
'green' : $row[
'ob_classification'];
327 $vars[
'licenseSelectorName'] =
'licenseSelector[]';
328 $vars[
'licenseSelectorId'] =
'licenseSelectorId';
329 $vars[
'candidateSelectorName'] =
'candidateSelector[]';
330 $vars[
'candidateSelectorId'] =
'candidateSelectorId';
331 $scripts =
"<script src='scripts/tools.js' type='text/javascript'></script>
332 <script src='scripts/select2.full.min.js'></script>
333 <script type='text/javascript'>
334 $('#licenseSelectorId').select2({'placeholder': 'Select licenses associated with this obligation'});
336 <script type='text/javascript'>
337 $('#candidateSelectorId').select2({'placeholder': 'Select candidate licenses associated with this obligation'});
339 <script type='text/javascript'>
340 function confirmDeletion() {
342 var updateform = document.forms['Updatefm'];
343 var delinput = document.createElement('input');
344 delinput.name = 'del';
346 if (confirm('Are you sure?')) {
347 delinput.value = 'y';
350 delinput.value = 'n';
352 updateform.appendChild(delinput);
357 $allVars = array_merge($vars,$row);
358 return $this->
renderString(
'admin_obligation-upload_form.html.twig', $allVars);
368 $obId = intval($_POST[
'ob_pk']);
369 $topic = StringOperation::replaceUnicodeControlChar(
trim($_POST[
'ob_topic']));
370 $licnames = $_POST[
'licenseSelector'];
371 $candidatenames = $_POST[
'candidateSelector'];
372 $text = StringOperation::replaceUnicodeControlChar(
trim($_POST[
'ob_text']));
373 $comment = StringOperation::replaceUnicodeControlChar(
trim($_POST[
'ob_comment']));
376 $text = _(
"ERROR: The obligation topic is empty.");
377 return "<b>$text</b><p>";
381 $text = _(
"ERROR: The obligation text is empty.");
382 return "<b>$text</b><p>";
387 "ERROR: The obligation topic and text already exist in the obligation list. Obligation not updated.");
388 return "<b>$text</b><p>";
391 $sql =
"UPDATE obligation_ref SET ob_active=$2, ob_type=$3, ob_modifications=$4, ob_topic=$5, ob_md5=md5($6), ob_text=$6, ob_classification=$7, ob_text_updatable=$8, ob_comment=$9 WHERE ob_pk=$1";
396 $_POST[
'ob_modifications'],
399 $_POST[
'ob_classification'],
400 $_POST[
'ob_text_updatable'],
402 $this->
dbManager->prepare($stmt=__METHOD__.
".update", $sql);
407 $newCandidateLicenses = $this->
addNewLicenses($candidatenames,$obId,
true);
411 $unassociatedCandidateLicenses = $this->
removeLicenses($candidatenames,$obId,
true);
413 $ob =
"Obligation '$topic' was updated - ";
414 $ob .= $newAssociatedLicenses ?
"New licenses: '$newAssociatedLicenses' - " :
"";
415 $ob .= $newCandidateLicenses ?
"New candidate licenses: '$newCandidateLicenses' - " :
"";
416 $ob .= $unassociatedLicenses ?
"Removed licenses: '$unassociatedLicenses' - " :
"";
417 $ob .= $unassociatedCandidateLicenses ?
"Removed candidate licenses: '$unassociatedCandidateLicenses'" :
"";
430 $topic = StringOperation::replaceUnicodeControlChar(
trim($_POST[
'ob_topic']));
431 $licnames = empty($_POST[
'licenseSelector']) ? array() : $_POST[
'licenseSelector'];
432 $candidatenames = empty($_POST[
'candidateSelector']) ? array() : $_POST[
'candidateSelector'];
433 $text = StringOperation::replaceUnicodeControlChar(
trim($_POST[
'ob_text']));
434 $comment = StringOperation::replaceUnicodeControlChar(
trim($_POST[
'ob_comment']));
438 $text = _(
"ERROR: The obligation topic is empty.");
439 return "<b>$text</b><p>";
443 $text = _(
"ERROR: The obligation text is empty.");
444 return "<b>$text</b><p>";
447 if (empty($licnames) && empty($candidatenames)) {
448 $message = _(
"ERROR: There are no licenses associated with this topic.");
449 return "<b>$message</b><p>";
454 "ERROR: The obligation topic and text already exist in the obligation list. Obligation not added.");
455 return "<b>$message</b><p>";
458 $stmt = __METHOD__.
'.ob';
459 $sql =
"INSERT into obligation_ref (ob_active, ob_type, ob_modifications, ob_topic, ob_md5, ob_text, ob_classification, ob_text_updatable, ob_comment) VALUES ($1, $2, $3, $4, md5($5), $5, $6, $7, $8) RETURNING ob_pk";
462 array($_POST[
'ob_active'],
464 $_POST[
'ob_modifications'],
467 $_POST[
'ob_classification'],
468 $_POST[
'ob_text_updatable'],
470 $row = $this->
dbManager->fetchArray($res);
471 $obId = $row[
'ob_pk'];
474 $candidateLicenses = $this->
addNewLicenses($candidatenames, $obId, True);
476 $message .=
"Obligation '$topic' associated with: ";
477 $message .= $associatedLicenses ?
"licenses '$associatedLicenses' " :
"";
478 $message .= ($associatedLicenses && $candidateLicenses) ?
"and " :
"";
479 $message .= $candidateLicenses ?
"candidates licenses '$candidateLicenses' " :
"";
480 $message .=
"(id=$obId) was added.<p>";
492 $this->obligationMap->deleteObligation($_POST[
'ob_pk']);
494 return "<p>Obligation has been deleted.</p>";
507 if (!empty($shortnames)) {
509 foreach ($shortnames as $license) {
510 $licIds = $this->obligationMap->getIdFromShortname($license,$candidate);
511 $newLic = $this->obligationMap->associateLicenseFromLicenseList($obId,
512 $licIds, $candidate);
514 if ($licList ==
"") {
515 $licList =
"$license";
517 $licList .=
";$license";
537 $unassociatedLicenses =
"";
538 $licenses = $this->obligationMap->getLicenseList($obId, $candidate);
539 $current = explode(
";", $licenses);
540 if (! empty($shortnames)) {
541 $obsoleteLicenses = array_diff($current, $shortnames);
543 $obsoleteLicenses = $current;
546 if ($obsoleteLicenses) {
547 foreach ($obsoleteLicenses as $toBeRemoved) {
548 $licIds = $this->obligationMap->getIdFromShortname($toBeRemoved,
550 $this->obligationMap->unassociateLicenseFromLicenseList($obId, $licIds,
552 if ($unassociatedLicenses ==
"") {
553 $unassociatedLicenses =
"$toBeRemoved";
555 $unassociatedLicenses .=
";$toBeRemoved";
560 return $unassociatedLicenses;
This is the Plugin class. All plugins should:
renderString($templateName, $vars=null)
renderScripts($scripts)
Render JavaScript in the template's footer.
Wrapper class for obligation map.
Output()
This function is called when user output is requested. This function is responsible for content....
ObligationTopic($topic)
Build the input form.
isObligationTopicAndTextBlocked($obId, $topic, $text)
check if the text of this obligation is existing
addNewLicenses($shortnames, $obId, $candidate=false)
Associate selected licenses to the obligation.
Updatefm($ob_pk)
Update forms.
Inputfm()
Build the input form.
Deldb()
Remove obligation_ref from the database and unassociate licenses.
Adddb()
Add a new obligation_ref to the database.
ObligationTopics()
return an array of all obligation topics from the DB
Updatedb()
Update the database.
removeLicenses($shortnames, $obId, $candidate=false)
Unassociate selected licenses to the obligation.
__construct()
base constructor. Most plugins will just use this
RegisterMenus()
Customize submenus.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
DB2ValArray($Table, $ValCol, $Uniq=false, $Where="")
Create an array by using table rows to source the values.
Traceback_uri()
Get the URI without query to this location.
Array2SingleSelect($KeyValArray, $SLName="unnamed", $SelectedVal="", $FirstEmpty=false, $SelElt=true, $Options="", $ReturnKey=true)
Build a single choice select pulldown.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
fo_dbManager * dbManager
fo_dbManager object