<commit_before><?php
/********************************************************************************
*                                                                               *
*   Copyright 2012 <NAME> (<EMAIL>)                      *
*   http://www.elabftw.net/                                                     *
*                                                                               *
********************************************************************************/

/********************************************************************************
*  This file is part of eLabFTW.                                                *
*                                                                               *
*    eLabFTW is free software: you can redistribute it and/or modify            *
*    it under the terms of the GNU Affero General Public License as             *
*    published by the Free Software Foundation, either version 3 of             *
*    the License, or (at your option) any later version.                        *
*                                                                               *
*    eLabFTW is distributed in the hope that it will be useful,                 *
*    but WITHOUT ANY WARRANTY; without even the implied                         *
*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR                    *
*    PURPOSE.  See the GNU Affero General Public License for more details.      *
*                                                                               *
*    You should have received a copy of the GNU Affero General Public           *
*    License along with eLabFTW.  If not, see <http://www.gnu.org/licenses/>.   *
*                                                                               *
********************************************************************************/
// inc/editXP.php
?>
<script src="js/tinymce/tinymce.min.js"></script>
<?php
// ID
if(isset($_GET['id']) && !empty($_GET['id']) && is_pos_int($_GET['id'])){
    $id = $_GET['id'];
} else {
    die("The id parameter in the URL isn't a valid item ID.");
}

// SQL for editXP
$sql = "SELECT * FROM experiments WHERE id = ".$id;
$req = $bdd->prepare($sql);
$req->execute();
$exp_data = $req->fetch();

$sql = "SELECT rev_id, rev_body, rev_title, rev_reaction_id FROM revisions WHERE rev_id = :revid";
$req = $bdd->prepare($sql);
$req->execute(array(
		'revid' => $exp_data['rev_id']
	));
$rev_data = $req->fetch();


// Do some chemistry-specific stuff
if($exp_data['type'] === 'chemsingle' || $exp_data['type'] === 'chemparallel') {
	// SQL to get our reaction box and probably do other stuff later...
	if($rev_data['rev_reaction_id'] != NULL) {
		$sql = "SELECT * FROM reactions WHERE rxn_id = ".$rev_data['rev_reaction_id'];
		$req = $bdd->prepare($sql);
		$req->execute();
		$rxn_data = $req->fetch();		
	} else {
		$rxn_data['rxn_mdl'] = "";
	}
	
	$gridDatadb = array();
	$sql = "SELECT * FROM rxn_stoichiometry WHERE rev_id = {$exp_data['rev_id']}";
	$req = $bdd->prepare($sql);
	$req->execute();
	if ($req->rowcount() != 0) {
		while($gridRow = $req->fetch(PDO::FETCH_ASSOC)) {
			$gridDatadb[] = $gridRow;
		}
	}
		
	
	
	// now to make our reaction box ?>
	 <!-- first just make the grid data available -->
	<script type="text/javascript">var gridData = <?php echo json_encode($gridDatadb);?>;
		for (i in gridData) {
			for(j in gridData[i]) {
				if(gridData[i][j] === null) {
					delete gridData[i][j];
				}
			}
		}
		</script>
	<!--these four are required by the ChemDoodle Web Components library-->
	<meta http-equiv="X-UA-Compatible" content="chrome=1">
	<link rel="stylesheet" href="js/chemdoodleweb/ChemDoodleWeb.css" type="text/css">
	<script type="text/javascript" src="js/chemdoodleweb/ChemDoodleWeb-libs.js"></script>  
    <script type="text/javascript" src="js/chemdoodleweb/ChemDoodleWeb.js"></script> 	
	<!--these three are required by the SketcherCanvas plugin-->
	<link rel="stylesheet" href="js/chemdoodleweb/sketcher/jquery-ui-1.9.2.custom.css" type="text/css">
	<script type="text/javascript" src="js/chemdoodleweb/sketcher/jquery-ui-1.9.2.custom.min.js"></script>
	<script type="text/javascript" src="js/chemdoodleweb/sketcher/ChemDoodleWeb-sketcher.js"></script> 
	
	<!--now we load slickgrid for the stoichiometry table -->
	<link rel="stylesheet" href="js/slickgrid/slick.grid.css" type="text/css">
	<link rel="stylesheet" href="css/stoich-grid.css" type="text/css">
    <link rel="stylesheet" href="js/slickgrid/controls/slick.columnpicker.css" type="text/css">
	<script type="text/javascript" src="js/slickgrid/lib/jquery.event.drag-2.2.js"></script>
	<script type="text/javascript" src="js/slickgrid/lib/jquery.event.drop-2.2.js"></script>
	<script type="text/javascript" src="js/slickgrid/slick.dataview.js"></script>
	<script type="text/javascript" src="js/slickgrid/controls/slick.columnpicker.js"></script>
	<script type="text/javascript" src="js/slickgrid/plugins/slick.rowselectionmodel.js"></script>
	<script type="text/javascript" src="js/slickgrid/slick.core.js"></script>
	<script type="text/javascript" src="js/slickgrid/slick.editors.js"></script>
	<script type="text/javascript" src="js/slickgrid/slick.formatters.js"></script>
	<script type="text/javascript" src="js/slickgrid/slick.grid.js"></script>
	<script type="text/javascript" src="js/chem-editors.js"></script> 	
	<script type="text/javascript" src="js/chem-formatters.js"></script> 	
	<script type="text/javascript" src="js/stoic-table-edit.js"></script> 	
	<script type="text/javascript" src="js/unit-converters.js"></script> 	

			
	
	<script type="text/javascript">var rxn = <?php echo json_encode($rxn_data['rxn_mdl']);?>;</script>

	<?php 
	
	
}

// Check id is owned by connected user
if ($exp_data['userid_creator'] != $_SESSION['userid']) {
    echo ("<ul class='errors'>You are trying to edit an experiment which is not yours.</ul>");
    require_once('inc/footer.php');
    exit();
}

// Check for lock
if ($exp_data['locked'] == 1) {
    die("Item is locked. Can't edit.");
}

// BEGIN CONTENT
?>
<section id='view_xp_item' class='item <?php echo $exp_data['status'];?>'>
<a class='align_right' href='delete_item.php?id=<?php echo $id;?>&type=exp' onClick="return confirm('Delete this experiment ?');"><img src='themes/<?php echo $_SESSION['prefs']['theme'];?>/img/trash.png' title='delete' alt='delete' /></a>
<!-- ADD TAG FORM --><commit_msg>Slightly cleanup how we load some external js in editXP<commit_after><?php
/********************************************************************************
*                                                                               *
*   Copyright 2012 <NAME> (<EMAIL>)                      *
*   http://www.elabftw.net/                                                     *
*                                                                               *
********************************************************************************/

/********************************************************************************
*  This file is part of eLabFTW.                                                *
*                                                                               *
*    eLabFTW is free software: you can redistribute it and/or modify            *
*    it under the terms of the GNU Affero General Public License as             *
*    published by the Free Software Foundation, either version 3 of             *
*    the License, or (at your option) any later version.                        *
*                                                                               *
*    eLabFTW is distributed in the hope that it will be useful,                 *
*    but WITHOUT ANY WARRANTY; without even the implied                         *
*    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR                    *
*    PURPOSE.  See the GNU Affero General Public License for more details.      *
*                                                                               *
*    You should have received a copy of the GNU Affero General Public           *
*    License along with eLabFTW.  If not, see <http://www.gnu.org/licenses/>.   *
*                                                                               *
********************************************************************************/
// inc/editXP.php
?>
<script src="js/tinymce/tinymce.min.js"></script>
<?php
// ID
if(isset($_GET['id']) && !empty($_GET['id']) && is_pos_int($_GET['id'])){
    $id = $_GET['id'];
} else {
    die("The id parameter in the URL isn't a valid item ID.");
}

// SQL for editXP
$sql = "SELECT * FROM experiments WHERE id = ".$id;
$req = $bdd->prepare($sql);
$req->execute();
$exp_data = $req->fetch();

$sql = "SELECT rev_id, rev_body, rev_title, rev_reaction_id FROM revisions WHERE rev_id = :revid";
$req = $bdd->prepare($sql);
$req->execute(array(
		'revid' => $exp_data['rev_id']
	));
$rev_data = $req->fetch();


// Do some chemistry-specific stuff
if($exp_data['type'] === 'chemsingle' || $exp_data['type'] === 'chemparallel') {
	// SQL to get our reaction box and probably do other stuff later...
	if($rev_data['rev_reaction_id'] != NULL) {
		$sql = "SELECT * FROM reactions WHERE rxn_id = ".$rev_data['rev_reaction_id'];
		$req = $bdd->prepare($sql);
		$req->execute();
		$rxn_data = $req->fetch();		
	} else {
		$rxn_data['rxn_mdl'] = "";
	}
	
	$gridDatadb = array();
	$sql = "SELECT * FROM rxn_stoichiometry WHERE rev_id = {$exp_data['rev_id']}";
	$req = $bdd->prepare($sql);
	$req->execute();
	if ($req->rowcount() != 0) {
		while($gridRow = $req->fetch(PDO::FETCH_ASSOC)) {
			$gridDatadb[] = $gridRow;
		}
	}
		
	
	
	// now to make our reaction box ?>
	 <!-- first just make the grid data available -->
	<script type="text/javascript">var gridData = <?php echo json_encode($gridDatadb);?>;
		for (i in gridData) {
			for(j in gridData[i]) {
				if(gridData[i][j] === null) {
					delete gridData[i][j];
				}
			}
		}
		
	// these four are required by the ChemDoodle Web Components library	
	$("head").append('<meta http-equiv="X-UA-Compatible" content="chrome=1">',
				'<link rel="stylesheet" href="js/chemdoodleweb/ChemDoodleWeb.css" type="text/css">',
				'<script type="text/javascript" src="js/chemdoodleweb/ChemDoodleWeb-libs.js"/>',
				'<script type="text/javascript" src="js/chemdoodleweb/ChemDoodleWeb.js"/>');
					
	// these three are required by the SketcherCanvas plugin
	$("head").append('<link rel="stylesheet" href="js/chemdoodleweb/sketcher/jquery-ui-1.9.2.custom.css" type="text/css">',
				'<script type="text/javascript" src="js/chemdoodleweb/sketcher/jquery-ui-1.9.2.custom.min.js"/>',
				'<script type="text/javascript" src="js/chemdoodleweb/sketcher/ChemDoodleWeb-sketcher.js"/>');

	// now all the slickgrid stuff
	$("head").append('<link rel="stylesheet" href="js/slickgrid/slick.grid.css" type="text/css">',
				'<link rel="stylesheet" href="css/stoich-grid.css" type="text/css">',
			    '<link rel="stylesheet" href="js/slickgrid/controls/slick.columnpicker.css" type="text/css">',
				'<script type="text/javascript" src="js/slickgrid/lib/jquery.event.drag-2.2.js"/>',
				'<script type="text/javascript" src="js/slickgrid/lib/jquery.event.drop-2.2.js"/>',
				'<script type="text/javascript" src="js/slickgrid/slick.dataview.js"/>',
				'<script type="text/javascript" src="js/slickgrid/controls/slick.columnpicker.js"/>',
				'<script type="text/javascript" src="js/slickgrid/plugins/slick.rowselectionmodel.js"/>',
				'<script type="text/javascript" src="js/slickgrid/slick.core.js"/>',
				'<script type="text/javascript" src="js/slickgrid/slick.editors.js"/>',
				'<script type="text/javascript" src="js/slickgrid/slick.formatters.js"/>',
				'<script type="text/javascript" src="js/slickgrid/slick.grid.js"/>',
				'<script type="text/javascript" src="js/chem-editors.js"/>', 	
				'<script type="text/javascript" src="js/chem-formatters.js"/>', 	
				'<script type="text/javascript" src="js/stoic-table-edit.js"/>', 	
				'<script type="text/javascript" src="js/unit-converters.js"/>'); 
				
		var rxn = <?php echo json_encode($rxn_data['rxn_mdl']);?>;
		</script>
	<?php 
	
	
}

// Check id is owned by connected user
if ($exp_data['userid_creator'] != $_SESSION['userid']) {
    echo ("<ul class='errors'>You are trying to edit an experiment which is not yours.</ul>");
    require_once('inc/footer.php');
    exit();
}

// Check for lock
if ($exp_data['locked'] == 1) {
    die("Item is locked. Can't edit.");
}

// BEGIN CONTENT
?>
<section id='view_xp_item' class='item <?php echo $exp_data['status'];?>'>
<a class='align_right' href='delete_item.php?id=<?php echo $id;?>&type=exp' onClick="return confirm('Delete this experiment ?');"><img src='themes/<?php echo $_SESSION['prefs']['theme'];?>/img/trash.png' title='delete' alt='delete' /></a>
<!-- ADD TAG FORM -->
{'fraction_non_alphanumeric': 0.21064456151224048, 'fraction_numerical': 0.0027889680818097306, 'mean_word_length': 2.697794328272701, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1301097', 'n_tokens_mistral': 4108, 'n_tokens_neox': 3837, 'n_words': 849}