PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/s3db3.5.10/resource/instance.php

https://code.google.com/p/s3db/
PHP | 250 lines | 144 code | 75 blank | 31 comment | 23 complexity | 89016e5821b082c13b0dcd1cd8c04b0d 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['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']:$instance_info['class_id'];
  35. if($instance_id=='')
  36. {
  37. echo "Please provide an instance_id";
  38. }
  39. elseif(!$instance_info['view'])
  40. {echo ('User does not have permission in this instance');
  41. exit;
  42. }
  43. elseif($instance_info['add_data'])
  44. {
  45. include('../action.header.php');
  46. #add the instance header and the insertall
  47. echo '<table width="100%">';
  48. echo '<tr><td class="nav_menu">';
  49. echo '<br /><br />[ <a href="#" onClick="window.location=\''.$action['instanceform'].'\'"> Insert All Page </a>]';
  50. #include the header for the instance
  51. include('instance.header.php');
  52. #if there are any rules, print a grid with the rules header and the button to add a statement
  53. #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
  54. $s3ql=compact('user_id','db');
  55. $s3ql['from'] = 'rules';
  56. $s3ql['where']['subject_id'] = $instance_info['class_id'];
  57. #$s3ql['where']['object'] = "!='UID'";
  58. $rules = S3QLaction($s3ql);
  59. $I = compact('instance_info', 'db', 'user_id', 'rules','project_id');
  60. #}
  61. if(is_array($rules))
  62. echo render_statements($I); #print the statements together with the rules.
  63. }
  64. function render_statements($I)
  65. {$action = $GLOBALS['action']; #all the possible links were separated ina script that gets always included
  66. extract($I);
  67. $_SESSION['current_color']='0';
  68. $_SESSION['previous_verb']='';
  69. #display all the rules in this class where the user has permission
  70. $s3ql=compact('user_id','db');
  71. $s3ql['select']='*';
  72. $s3ql['from']='statements';
  73. $s3ql['where']['instance_id']=$instance_info['instance_id'];
  74. $statements = S3QLaction($s3ql);
  75. #echo '<pre>';print_r($statements);
  76. #exit;
  77. #divide them by rules
  78. if(is_array($statements)){
  79. foreach ($statements as $stat_info) {
  80. $stats_per_rule[$stat_info['rule_id']][$stat_info['statement_id']] = $stat_info;
  81. }
  82. if(is_array($rules))
  83. {$rule_ids = array_map('grab_rule_id', $rules);
  84. $tRules = array_combine($rule_ids, $rules);
  85. }
  86. if(is_array($stats_per_rule) && is_array($tRules))
  87. {
  88. $stats ='';
  89. $index = 1;
  90. foreach($stats_per_rule as $rule_id=>$exist_stats)
  91. {
  92. if($tRules[$rule_id]['object']!='UID' && $tRules[$rule_id]['verb']!='has UID'){
  93. $subject = $tRules[$rule_id]['subject'];
  94. $verb = $tRules[$rule_id]['verb'];
  95. $object = $tRules[$rule_id]['object'];
  96. $rule_id = $tRules[$rule_id]['rule_id'];
  97. #$rule_notes = preg_replace('/\(.*\)/', '', $rules[$i]['notes']);
  98. $rule_notes = $tRules[$rule_id]['notes'];
  99. $stats .= sprintf("\n%s\n", '<table width="100%" border="0"><tr bgcolor="lightyellow"><td colspan="2">');
  100. $stats .= sprintf("%s\n", ($index+$i).'. '.printVerbinColor($verb).' | <font size=4><b>'.$object.'</b></font> </td></tr><tr><td>&nbsp;&nbsp;<font size-=2>'.$rule_notes.'</font></td><td align="right">');
  101. if($tRules[$rule_id]['add_data'])
  102. $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\')">');
  103. $stats .= sprintf("%s\n", ' </td></tr>');
  104. #$exist_stats = get_exist_stats($instance_info['resource_id'], $rule_id, $db);
  105. #$s3ql= compact('user_id', 'db');
  106. #$s3ql['from'] = 'statements';
  107. #$s3ql['where']['project_id'] = $project_id;
  108. #$s3ql['where']['resource_id'] = $instance_info['resource_id'];
  109. #$s3ql['where']['rule_id'] = $rule_id;
  110. #$exist_stats = S3QLaction($s3ql);
  111. #$exist_stats = include_statement_acl($exist_stats, $user_id, $db);
  112. #echo '<pre>';print_r($exist_stats);
  113. $stat ='';
  114. $stat .= sprintf("%s\n", ' <tr><td colspan="2" style="color: navy; font-size: normal">');
  115. if(is_array($exist_stats))
  116. $stat .= render_substatements_without_grid($exist_stats, $db);
  117. //$stat .= render_substatements($exist_stats, 'value', 'DESC');
  118. $stat .= sprintf("%s\n", ' </td></tr>');
  119. $stats .= $stat;
  120. $stats .= sprintf("%s\n", ' <tr><td colspan="2"><br>');
  121. $stats .= sprintf("%s\n", ' </td></tr>');
  122. $stats .= sprintf("%s\n", '</table>');
  123. }
  124. }
  125. }
  126. }
  127. return $stats;
  128. }
  129. function render_substatements_without_grid($exist_stats, $db)
  130. {$action=$GLOBALS['action'];
  131. $substats = '<table width="100%" border="0">';
  132. if(is_array($exist_stats))
  133. {
  134. #echo '<pre>';print_r($exist_stats);
  135. foreach($exist_stats as $i => $value)
  136. {
  137. #if(object_is_resource())
  138. if($exist_stats[$i]['object_id']!='')
  139. {
  140. #if the value is numeric and not a file, put a button
  141. $substats .= '<tr><td colspan="6"><input type="button" size="10" value="'.$exist_stats[$i]['object_notes'].'" onClick="window.open(\''.$action['instance'].'&instance_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>';
  142. }
  143. else
  144. {
  145. if($exist_stats[$i]['file_name'] =='')
  146. $substats .= "<tr><td colspan=6><font color=dodgerblue size=3><b>".urldecode($exist_stats[$i]['value'])."</b></font></td></tr>";
  147. }
  148. if($exist_stats[$i]['change'])
  149. {
  150. $action_link = printStatementActionLink($exist_stats[$i]['statement_id']);
  151. }
  152. $account_id = $exist_stats[$i]['created_by'];
  153. if($exist_stats[$i]['file_name'] !='')
  154. {
  155. $statement_id = $exist_stats[$i]['statement_id'];
  156. $project_id = $exist_stats[$i]['project_id'];
  157. $resource_id = $exist_stats[$i]['resource_id'];
  158. $rule_id = $exist_stats[$i]['rule_id'];
  159. $file_name = $exist_stats[$i]['file_name'];
  160. if($exist_stats[$i]['file_size']!='')
  161. { $size = ceil($exist_stats[$i]['file_size']/1024);
  162. $file_size = ' ('.$size.' kb)';
  163. }
  164. $substats .= "<tr><td colspan=6><font color=dodgerblue size=3><b>File: <a href=".$action['download']."&resource_id=$resource_id&rule_id=$rule_id&statement_id=$statement_id>".$file_name.$file_size."<a/></b></font></td></tr>";
  165. }
  166. $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%>";
  167. if($exist_stats[$i]['change'])
  168. $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>";
  169. }
  170. $substats .= '</table>';
  171. //echo $substats;
  172. return $substats;
  173. }
  174. }
  175. ?>