PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/s3db3.5.10/item.php

https://github.com/drobbins/s3db
PHP | 228 lines | 140 code | 67 blank | 21 comment | 22 complexity | 78cf33ab1e6af26efcae67c3bdf67857 MD5 | raw file
  1. <?php
  2. #instance.php displays all statements in a certain instance and links to create more
  3. #Helena F Deus (helenadeus@gmail.com)
  4. ini_set('display_errors',0);
  5. if($_REQUEST['su3d'])
  6. ini_set('display_errors',1);
  7. if($_SERVER['HTTP_X_FORWARDED_HOST']!='')
  8. $def = $_SERVER['HTTP_X_FORWARDED_HOST'];
  9. else
  10. $def = $_SERVER['HTTP_HOST'];
  11. if(file_exists('config.inc.php'))
  12. {
  13. include('config.inc.php');
  14. }
  15. else
  16. {
  17. Header('Location: http://'.$def.'/s3db/');
  18. exit;
  19. }
  20. #just to know where we are...
  21. $thisScript = end(explode('/', $_SERVER['SCRIPT_FILENAME'])).'?'.$_SERVER['argv'][0];
  22. $key = $_GET['key'];
  23. #echo '<pre>';print_r($_GET);
  24. #Get the key, send it to check validity
  25. include_once('core.header.php');
  26. if($key)
  27. $user_id = get_entry('access_keys', 'account_id', 'key_id', $key, $db);
  28. else
  29. $user_id = $_SESSION['user']['account_id'];
  30. #Universal variables
  31. $instance_id = ($_REQUEST['item_id']!='')?$_REQUEST['item_id']:$_REQUEST['instance_id'];
  32. if($instance_id)
  33. $instance_info = URIinfo('I'.$instance_id, $user_id, $key, $db);
  34. $class_id = ($_REQUEST['class_id']!='')?$_REQUEST['class_id']:(($_REQUEST['collection_id']!='')?$_REQUEST['collection_id']:$instance_info['class_id']);
  35. if($instance_id=='')
  36. {
  37. echo "Please provide an item_id";
  38. exit;
  39. }
  40. elseif(!$instance_info)
  41. {
  42. echo "Item_id ".$instance_id." does not exist";
  43. exit;
  44. }
  45. elseif(!$instance_info['view'])
  46. {echo ('User does not have permission in this instance');
  47. exit;
  48. }
  49. else
  50. {
  51. include('action.header.php'); #add the instance header and the insertall
  52. echo '<table width="100%">';
  53. echo '<tr><td class="nav_menu">';
  54. if($instance_info['add_data'])
  55. echo '<br /><br />[ <a href="#" onClick="window.location=\''.$action['instanceform'].'\'"> Add Statements </a>]';
  56. }
  57. #include the header for the instance
  58. include('resource/instance.header.php');
  59. #if there are any rules, print a grid with the rules header and the button to add a statement
  60. #if (ereg('(1|2|3)', $projectAcl)) {#users that do not have access on the project and do not provide a project_id cannot see rules. Otherwise, there is no way of knowing which rules they were given access to
  61. $s3ql=compact('user_id','db');
  62. $s3ql['from'] = 'rules';
  63. $s3ql['where']['subject_id'] = $instance_info['class_id'];
  64. #$s3ql['where']['object'] = "!='UID'";
  65. $rules = S3QLaction($s3ql);
  66. #echo 'ola<pre>';print_r($rules);exit;
  67. $I = compact('instance_info', 'db', 'user_id', 'rules','project_id');
  68. #}
  69. if(is_array($rules))
  70. echo render_statements($I); #print the statements together with the rules.
  71. function render_statements($I)
  72. {$action = $GLOBALS['action']; #all the possible links were separated ina script that gets always included
  73. extract($I);
  74. $_SESSION['current_color']='0';
  75. $_SESSION['previous_verb']='';
  76. #display all the rules in this class where the user has permission
  77. $s3ql=compact('user_id','db');
  78. $s3ql['select']='*';
  79. $s3ql['from']='statements';
  80. $s3ql['where']['instance_id']=$instance_info['instance_id'];
  81. $statements = S3QLaction($s3ql);
  82. #echo '<pre>';print_r($statements);exit;
  83. #divide them by rules
  84. if(is_array($statements)){
  85. foreach ($statements as $stat_info) {
  86. $stats_per_rule[$stat_info['rule_id']][$stat_info['statement_id']] = $stat_info;
  87. }
  88. if(is_array($rules))
  89. {$rule_ids = array_map('grab_rule_id', $rules);
  90. $tRules = array_combine($rule_ids, $rules);
  91. }
  92. #echo '<pre>';print_r($stats_per_rule);exit;
  93. if(is_array($stats_per_rule) && is_array($tRules))
  94. {
  95. $stats ='';
  96. $index = 1;
  97. foreach($stats_per_rule as $rule_id=>$exist_stats)
  98. {
  99. if($tRules[$rule_id]['object']!='UID' && $tRules[$rule_id]['verb']!='has UID'){
  100. $subject = $tRules[$rule_id]['subject'];
  101. $verb = $tRules[$rule_id]['verb'];
  102. $object = $tRules[$rule_id]['object'];
  103. $rule_id = $tRules[$rule_id]['rule_id'];
  104. #$rule_notes = preg_replace('/\(.*\)/', '', $rules[$i]['notes']);
  105. $rule_notes = $tRules[$rule_id]['notes'];
  106. $stats .= sprintf("\n%s\n", '<table width="100%" border="0"><tr bgcolor="lightyellow"><td colspan="2">');
  107. $stats .= sprintf("%s\n", ($index++).'. '.printVerbinColor($verb).' | <font size=4><b>'.$object.'</b></font> (R'.$rule_id.') </td></tr><tr><td>&nbsp;&nbsp;<font size-=2>'.$rule_notes.'</font></td><td align="right">');
  108. if($tRules[$rule_id]['add_data'])
  109. $stats .= sprintf("%s\n",'<input type="button" value="Add" onClick="window.open(\''.$action['insertstatement'].'&rule_id='.$rule_id.'\', \'_blank\', \'width=600, height=500, location=no, titlebar=no, scrollbars=yes, resizable=yes\')">');
  110. $stats .= sprintf("%s\n", ' </td></tr>');
  111. $stat ='';
  112. $stat .= sprintf("%s\n", ' <tr><td colspan="2" style="color: navy; font-size: normal">');
  113. if(is_array($exist_stats))
  114. $stat .= render_substatements_without_grid($exist_stats, $db);
  115. //$stat .= render_substatements($exist_stats, 'value', 'DESC');
  116. $stat .= sprintf("%s\n", ' </td></tr>');
  117. $stats .= $stat;
  118. $stats .= sprintf("%s\n", ' <tr><td colspan="2"><br>');
  119. $stats .= sprintf("%s\n", ' </td></tr>');
  120. $stats .= sprintf("%s\n", '</table>');
  121. }
  122. }
  123. }
  124. }
  125. return $stats;
  126. }
  127. function render_substatements_without_grid($exist_stats, $db)
  128. {$action=$GLOBALS['action'];
  129. $substats = '<table width="100%" border="0">';
  130. if(is_array($exist_stats))
  131. {
  132. #echo '<pre>';print_r($exist_stats);exit;
  133. foreach($exist_stats as $i => $value)
  134. {
  135. #if(object_is_resource())
  136. if($exist_stats[$i]['file_name']=='') {
  137. if($exist_stats[$i]['object_id']!='')
  138. {#if the value is not a file, put a button
  139. $substats .= '<tr><td colspan="6"><input type="button" size="10" value="'.$exist_stats[$i]['object_notes'].'" onClick="window.open(\''.$action['item'].'&item_id='.$exist_stats[$i]['value'].'\', \'_blank\', \'width=700, height=600, location=no, titlebar=no, scrollbars=yes, resizable=yes\')">&nbsp;&nbsp;<font size=1 color=navy> (Id '.str_pad($exist_stats[$i]['value'], 6, '0', STR_PAD_LEFT).')</font></td></tr>';
  140. }
  141. else
  142. {
  143. $substats .= "<tr><td colspan=6><font color=dodgerblue size=3><b>".html_entity_decode($exist_stats[$i]['value'])."</b></font></td></tr>";
  144. }
  145. }
  146. else {
  147. $substats .= "<tr><td colspan=6><font color=dodgerblue size=3><b>File: <a href=".$action['download']."&statement_id=".$exist_stats[$i]['statement_id'].">".$exist_stats[$i]['file_name'].(($exist_stats[$i]['file_size']!='')?'('.ceil($exist_stats[$i]['file_size']/1024).' kb)':'')."<a/></b></font></td></tr>";
  148. }
  149. $substats .= "<tr><td width=50%>&nbsp;</td><td width=15%><font color=gray size=1>".substr($exist_stats[$i]['created_on'], 0, 19)."</font></td><td width=15%>";
  150. if($exist_stats[$i]['change'])
  151. {
  152. $action_link = printStatementActionLink($exist_stats[$i]['statement_id']);
  153. $substats .= "<font color=gray size=1>".find_user_loginID(array('account_id'=>$exist_stats[$i]['created_by'], 'db'=>$db))."</font></td><td width=10%><font color=gray size=1>".$exist_stats[$i]['notes']."</font></td><td width=10% align=right>".$action_link."</td></tr>";
  154. }
  155. }
  156. $substats .= '</table>';
  157. //echo $substats;
  158. return $substats;
  159. }
  160. }
  161. ?>