Changeset f99c6684930968116c96e4d4d55ea5e61e8b8efb
- Timestamp:
- 02/27/09 21:28:36
(4 years ago)
- Author:
- Umar Farooq <umar@omniti.com>
- git-committer:
- Umar Farooq <umar@omniti.com> 1235770116 +0000
- git-parent:
[7fa19b30101cf9c678ec724d925ea789184d8e80]
- git-author:
- Umar Farooq <umar@omniti.com> 1235770116 +0000
- Message:
when deleting a graph, user is now warned if it is used in a worksheet
closed ticket #95
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2f41995 |
rf99c668 |
|
| 10 | 10 | RewriteRule ^json/graph/info/([^/]*)$ graph_info.php?id=$1 [PT,QSA] |
|---|
| 11 | 11 | RewriteRule ^json/graph/store$ graph_store.php [PT,QSA] |
|---|
| 12 | | RewriteRule ^json/graph/forget/([^/]*)$ graph_delete.php?id=$1 [PT,QSA] |
|---|
| | 12 | RewriteRule ^json/graph/forget/([^/]+)/([^/]+)$ graph_delete.php?id=$1&force=$2 [PT,QSA] |
|---|
| 13 | 13 | RewriteRule ^json/graph/search$ graph_search_json.php [PT,QSA] |
|---|
| 14 | 14 | RewriteRule ^json/datapoint/search$ datapoint_search_json.php [PT,QSA] |
|---|
| re13244c |
rf99c668 |
|
| 5 | 5 | $db = Reconnoiter_DB::getDB(); |
|---|
| 6 | 6 | |
|---|
| 7 | | try { |
|---|
| 8 | | $db->deleteGraph($_GET['id']); |
|---|
| 9 | | print json_encode(array()); |
|---|
| | 7 | $force = $_GET['force']; |
|---|
| | 8 | $wsheets = $db->getWorksheetsByGraph($_GET['id']); |
|---|
| | 9 | |
|---|
| | 10 | if($wsheets && !$force) { |
|---|
| | 11 | print json_encode(array('refed' => $wsheets)); |
|---|
| 10 | 12 | } |
|---|
| 11 | | catch(Exception $e) { |
|---|
| 12 | | print json_encode(array('error' => $e->getMessage())); |
|---|
| | 13 | |
|---|
| | 14 | else if($force || !$wsheets) { |
|---|
| | 15 | try { |
|---|
| | 16 | $db->deleteGraph($_GET['id']); |
|---|
| | 17 | print json_encode(array()); |
|---|
| | 18 | } |
|---|
| | 19 | catch(Exception $e) { |
|---|
| | 20 | print json_encode(array('error' => $e->getMessage())); |
|---|
| | 21 | } |
|---|
| 13 | 22 | } |
|---|
| r259cc32 |
rf99c668 |
|
| 489 | 489 | return function() { |
|---|
| 490 | 490 | confirm("I will forget the current graph. Are you sure?", function(){ |
|---|
| 491 | | $.getJSON('json/graph/forget/' + graphid, |
|---|
| 492 | | function (r) { |
|---|
| 493 | | if(r.error) { modal_warning("Database Error!", r.error); } |
|---|
| 494 | | else { |
|---|
| 495 | | perform_graph_search_edit(params); |
|---|
| 496 | | } |
|---|
| 497 | | }); |
|---|
| 498 | | if(current_graph_id==graphid) {set_current_graph_id('');} |
|---|
| | 491 | $.getJSON('json/graph/forget/' + graphid + '/0', |
|---|
| | 492 | function (r) { |
|---|
| | 493 | if(r.refed) { |
|---|
| | 494 | var msg = "This graph is used in worksheet(s):<p>"; |
|---|
| | 495 | for(var wg in r.refed){ msg += "<br>"+r.refed[wg];} |
|---|
| | 496 | msg+="<p> Forgetting it will remove it from these worksheets as well. <p>Are you sure you want to forget it?"; |
|---|
| | 497 | confirm(msg, |
|---|
| | 498 | function() { |
|---|
| | 499 | $.getJSON('json/graph/forget/' + graphid + '/1', |
|---|
| | 500 | function(r) { |
|---|
| | 501 | if(r.error) { modal_warning("Database Error!", r.error); } |
|---|
| | 502 | else { perform_graph_search_edit(params);} |
|---|
| | 503 | }); |
|---|
| | 504 | }); |
|---|
| | 505 | } |
|---|
| | 506 | else { |
|---|
| | 507 | if(r.error) { modal_warning("Database Error!", r.error); } |
|---|
| | 508 | else { |
|---|
| | 509 | perform_graph_search_edit(params); |
|---|
| | 510 | } |
|---|
| | 511 | } |
|---|
| | 512 | }); |
|---|
| | 513 | if(current_graph_id==graphid) {set_current_graph_id('');} |
|---|
| 499 | 514 | }); |
|---|
| 500 | 515 | return false; |
|---|
| r9318ea7 |
rf99c668 |
|
| 423 | 423 | $sth->execute(array($ws_id, $graphid)); |
|---|
| 424 | 424 | } |
|---|
| 425 | | |
|---|
| 426 | | //TODO this should delete from saved_graphs_dep too |
|---|
| | 425 | function getWorksheetsByGraph($graphid){ |
|---|
| | 426 | |
|---|
| | 427 | $sth = $this->db->prepare("select title from |
|---|
| | 428 | (select sheetid from prism.saved_worksheets_dep |
|---|
| | 429 | where prism.saved_worksheets_dep.graphid=?) as rel_swd |
|---|
| | 430 | natural join prism.saved_worksheets"); |
|---|
| | 431 | |
|---|
| | 432 | $sth->execute(array($graphid)); |
|---|
| | 433 | |
|---|
| | 434 | $rv = array(); |
|---|
| | 435 | while($row = $sth->fetch()) { |
|---|
| | 436 | $rv[] = $row['title']; |
|---|
| | 437 | } |
|---|
| | 438 | return $rv; |
|---|
| | 439 | } |
|---|
| | 440 | //this will also delete from saved_graphs_dep by cascade, so better call getWorksheetsByGraph to check first |
|---|
| 427 | 441 | function deleteGraph($id) { |
|---|
| 428 | 442 | $sth = $this->db->prepare("delete from prism.saved_graphs |
|---|
| r1ce987a |
rf99c668 |
|
| 71 | 71 | for ($point = 0; $point < count($a[$index]['data']); $point++){ |
|---|
| 72 | 72 | if( ($a[$bottom]['data'][$point][1] != "") && ($a[$index]['data'][$point][1] != "")) { |
|---|
| 73 | | error_log("adding value".$a[$bottom]['data'][$point][1]); |
|---|
| 74 | 73 | $tmp = $a[$index]['data'][$point][1] + $a[$bottom]['data'][$point][1]; |
|---|
| 75 | 74 | $a[$index]['data'][$point][1] = "$tmp"; |
|---|