Inheritance: extends Eloquent
コード例 #1
0
ファイル: exp_sys.php プロジェクト: qxj/exp-sys-toy
 private function _build()
 {
     $deploy = $this->_get_deploy();
     // get domains
     $domains = array();
     foreach ($deploy->{'domains'} as $d) {
         $domain = Domain::fromJson($d);
         $domains[$domain->getId()] = $domain;
         Logger::debug("load domain %s", $domain->toString());
     }
     // get layers
     foreach ($deploy->{'layers'} as $l) {
         $domain = $domains[$l->{'domain_id'}];
         $layer = new Layer($l->{'id'}, $domain);
         $this->_layers[$l->{'id'}] = $layer;
         Logger::debug("load layer %s", $layer->toString());
     }
     // assign experiments
     foreach ($deploy->{'experiments'} as $e) {
         $exp = Experiment::fromJson($e);
         $this->_exps[$exp->getId()] = $exp;
         $layer = $this->_layers[$exp->getLayerId()];
         $layer->assign($exp);
         Logger::debug("load exp %s", $exp->toString());
     }
     foreach ($deploy->{'parameters'} as $p) {
         $param = Parameter::fromJson($p);
         $this->_baseParams[$param->getName()] = $param->getValue();
         Logger::debug("load param %s => %s", $param->getName(), $param->getValue());
     }
 }
コード例 #2
0
ファイル: Experiments.php プロジェクト: lamenath/fbp
 /**
  * Parses a given experiments. Not meant to be used except for testing.
  *
  * @param  \stdClass $json the json bit retrieved from the API that represents experiments.
  * @return \Prismic\Experiments e manipulable object for that experiments.
  */
 public static function parse(\stdClass $json)
 {
     return new Experiments(array_map(function ($exp) {
         return Experiment::parse($exp);
     }, $json->draft), array_map(function ($exp) {
         return Experiment::parse($exp);
     }, $json->running));
 }
コード例 #3
0
ファイル: Deployment.php プロジェクト: myna/myna-php
 /**
  * Construct a Deployment from an Array of data, typically from
  * JSON from the API.
  */
 public static function fromArray($options)
 {
     $name = "\\Myna\\Data\\Deployment::fromArray";
     $uuid = \Myna\Arr::get_or_error($options, 'uuid', $name);
     $apiKey = \Myna\Arr::get_or_error($options, 'apiKey', $name);
     $apiRoot = \Myna\Arr::get_or_error($options, 'apiRoot', $name);
     $latest = \Myna\Arr::get_or_error($options, 'latest', $name);
     $experiments = array();
     $expts = \Myna\Arr::get($options, 'experiments', array());
     foreach ($expts as $expt) {
         array_push($experiments, Experiment::fromArray($expt));
     }
     return new Deployment($uuid, $apiKey, $apiRoot, $latest, $experiments);
 }
コード例 #4
0
 public function actionPxInfoManagement()
 {
     if (!isset($_GET['id'])) {
         $this->redirect("/user/view_profile");
     } else {
         $dataset = Dataset::model()->findByPk($_GET['id']);
         if (!$dataset) {
             Yii::log('dataset id not found', 'debug');
             $this->redirect("/user/view_profile");
         }
         if ($dataset->submitter_id != Yii::app()->user->id) {
             Yii::log('not the owner', 'debug');
             Yii::app()->user->setFlash('keyword', "You are not the owner of dataset");
             $this->redirect("/user/view_profile");
         }
         # load attributes
         $keywordsAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_keywords'));
         $sppAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_sample_processing_protocol'));
         $dppAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_data_processing_protocol'));
         $expTypeAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_experiment_type'));
         $instrumentAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_instrument'));
         $quantificationAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_quantification'));
         $modificationAttr = Attribute::model()->findByAttributes(array('attribute_name' => 'PX_modification'));
         if (!$keywordsAttr or !$sppAttr or !$dppAttr or !$expTypeAttr or !$instrumentAttr or !$quantificationAttr or !$modificationAttr) {
             Yii::app()->user->setFlash('keyword', "Attr cannot be found.");
             Yii::log("Attr cannot be found.", 'debug');
             $this->redirect("/user/view_profile");
         }
         # create new pxForm for validation and store px info into pxForm
         $pxForm = new PxInfoForm();
         # load keywords
         $keywords = DatasetAttributes::model()->findByAttributes(array('dataset_id' => $dataset->id, 'attribute_id' => $keywordsAttr->id));
         if (!$keywords) {
             $keywords = new DatasetAttributes();
             $keywords->dataset_id = $dataset->id;
             $keywords->attribute_id = $keywordsAttr->id;
         }
         $pxForm->keywords = $keywords->value;
         # load sample processing protocol
         $criteria = new CDbCriteria();
         $criteria->join = 'LEFT JOIN sample s on (t.sample_id = s.id) LEFT JOIN dataset_sample ds on (ds.sample_id = s.id)';
         $criteria->addCondition('ds.dataset_id = ' . $dataset->id);
         $criteria->addCondition('t.attribute_id = ' . $sppAttr->id);
         $spp = SampleAttribute::model()->find($criteria);
         if ($spp) {
             # get one spp
             $pxForm->spp = $spp->value;
         }
         # load experiment first, if not create one
         $experiment = Experiment::model()->findByAttributes(array('dataset_id' => $dataset->id));
         if (!$experiment) {
             #create new experiment
             $experiment = new Experiment();
             $experiment->experiment_type = 'proteomic';
             $experiment->experiment_name = 'PX "' . $dataset->title . '"';
             $experiment->dataset_id = $dataset->id;
             $experiment->save(false);
         }
         # load data processing protocol
         $dpp = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $dppAttr->id));
         if (!$dpp) {
             $dpp = new ExpAttributes();
             $dpp->exp_id = $experiment->id;
             $dpp->attribute_id = $dppAttr->id;
         }
         $pxForm->dpp = $dpp->value;
         # load experiment type
         $expType = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $expTypeAttr->id));
         if (!$expType) {
             # set default experiment type
             $expType = new ExpAttributes();
             $expType->exp_id = $experiment->id;
             $expType->attribute_id = $expTypeAttr->id;
             $expType->value = CJSON::encode(array());
         }
         $expTypeVal = CJSON::decode($expType->value);
         $pxForm->experimentType = $expTypeVal;
         if (isset($expTypeVal['Other'])) {
             $pxForm->exTypeOther = $expTypeVal['Other'];
         }
         # load instrument
         $instrument = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $instrumentAttr->id));
         if (!$instrument) {
             # set default instrument
             $instrument = new ExpAttributes();
             $instrument->exp_id = $experiment->id;
             $instrument->attribute_id = $instrumentAttr->id;
             $instrument->value = CJSON::encode(array());
         }
         $insVal = CJSON::decode($instrument->value);
         $pxForm->instrument = $insVal;
         if (isset($insVal['Other'])) {
             $pxForm->instrumentOther = $insVal['Other'];
         }
         # load quantification
         $quantification = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $quantificationAttr->id));
         if (!$quantification) {
             # set default quantification
             $quantification = new ExpAttributes();
             $quantification->exp_id = $experiment->id;
             $quantification->attribute_id = $quantificationAttr->id;
             $quantification->value = CJSON::encode(array());
         }
         $quanVal = CJSON::decode($quantification->value);
         $pxForm->quantification = $quanVal;
         if (isset($quanVal['Other'])) {
             $pxForm->quantificationOther = $quanVal['Other'];
         }
         # load modification
         $modification = ExpAttributes::model()->findByAttributes(array('exp_id' => $experiment->id, 'attribute_id' => $modificationAttr->id));
         if (!$modification) {
             # set default modificaiton
             $modification = new ExpAttributes();
             $modification->exp_id = $experiment->id;
             $modification->attribute_id = $modificationAttr->id;
             $modification->value = CJSON::encode(array());
         }
         $modiVal = CJSON::decode($modification->value);
         $pxForm->modification = $modiVal;
         if (isset($modiVal['Other'])) {
             $pxForm->modificationOther = $modiVal['Other'];
         }
         if (isset($_POST['PxInfoForm'])) {
             # default is save and quit, redirect to user view_profile page
             $isSubmit = false;
             if (isset($_POST['submit-btn'])) {
                 # if user click submit, then submit the dataset
                 $isSubmit = true;
             }
             # store px Info
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 $attrs = $_POST['PxInfoForm'];
                 $pxForm->attributes = $attrs;
                 if ($pxForm->validate()) {
                     #store keywords
                     $keywords->value = $attrs['keywords'];
                     #store dpp
                     $dpp->value = $attrs['dpp'];
                     if (isset($_POST['exType'])) {
                         #store exp type
                         $expTypeVal = $_POST['exType'];
                         if (isset($expTypeVal['Other'])) {
                             $expTypeVal['Other'] = $attrs['exTypeOther'] ? $attrs['exTypeOther'] : "";
                         }
                         $expType->value = CJSON::encode($expTypeVal);
                     }
                     if (isset($_POST['quantification'])) {
                         #store quantification
                         $quanVal = $_POST['quantification'];
                         if (isset($quanVal['Other'])) {
                             $quanVal['Other'] = $attrs['quantificationOther'] ? $attrs['quantificationOther'] : "";
                         }
                         $quantification->value = CJSON::encode($quanVal);
                     }
                     if (isset($_POST['instrument'])) {
                         #store instrument
                         $insVal = $_POST['instrument'];
                         if (isset($insVal['Other'])) {
                             $insVal['Other'] = $attrs['instrumentOther'] ? $attrs['instrumentOther'] : "";
                         }
                         $instrument->value = CJSON::encode($insVal);
                     }
                     if (isset($_POST['modification'])) {
                         #store modification
                         $modiVal = $_POST['modification'];
                         if (isset($modiVal['Other'])) {
                             $modiVal['Other'] = $attrs['modificationOther'] ? $attrs['modificationOther'] : "";
                         }
                         $modification->value = CJSON::encode($modiVal);
                     }
                     #store spp into each samples in the dataset
                     $samples = $dataset->allSamples;
                     $isSppsStored = $this->storeSpps($samples, $attrs['spp'], $sppAttr);
                     if ($isSppsStored and $keywords->save() and $dpp->save() and $expType->save() and $quantification->save() and $instrument->save() and $modification->save()) {
                         $transaction->commit();
                         if ($isSubmit) {
                             $this->redirect(array('/dataset/submit', 'id' => $dataset->id));
                         }
                         $this->redirect('/user/view_profile');
                     }
                 }
             } catch (Exception $e) {
                 $message = $e->getMessage();
                 Yii::log(print_r($message, true), 'error');
                 $transaction->rollback();
                 $this->redirect('/');
             }
         }
         $this->render('pxInfoManagement', array('model' => $dataset, 'pxForm' => $pxForm));
     }
 }
コード例 #5
0
<?php

/**
 * @author Anne L'Hôte <*****@*****.**>
 *
 * Called by scripts/experiments.js
 **/
require_once 'experiment.php';
$oExperimentClass = new Experiment();
$oExperiments = $oExperimentClass->getAllExperiments();
echo json_encode($oExperiments);
コード例 #6
0
<?php

/**
 * @author Anne L'Hôte <*****@*****.**>
 * 
 * Called by scripts/experiments.js
 **/
require_once 'experiment.php';
$iExperimentId = $_POST['experiment_id'];
$sPrefix = 'export_scores_';
$oExperimentClass = new Experiment();
$aGames = $oExperimentClass->getGamesFromExperiment($iExperimentId);
$aScores = array();
// 1. Check if this experiment id exists into database, return an error
$sQuery = "SELECT COUNT(id) AS c FROM mango_experiment WHERE id = {$iExperimentId}";
$oResult = $oExperimentClass->oDbConnection->query($sQuery);
$aRows = $oResult->fetch_array();
if ($aRows[c] == 0) {
    $aReturn['status'] = 'error';
    $aReturn['message'] = 'This experiment id doesn\'t exist into database!';
    echo json_encode($aReturn);
    exit;
}
// 2. Export final scores into CSV file
$sFileContent = "token,earning" . PHP_EOL;
$sQuery = "SELECT token,earning FROM mango_earning WHERE experiment_id = {$iExperimentId}";
$oResult = $oExperimentClass->oDbConnection->query($sQuery);
while ($aRow = $oResult->fetch_array()) {
    $sFileContent .= $aRow['token'] . ',' . $aRow['earning'] . PHP_EOL;
}
$fFile = fopen('../downloads/export_earning_' . $iExperimentId . '.csv', 'w+');
コード例 #7
0
 function LookupByUUID($uuid)
 {
     $safe_uuid = addslashes($uuid);
     $query_result = DBQueryWarn("select idx from experiments " . "where eid_uuid='{$safe_uuid}'");
     if (!$query_result || !mysql_num_rows($query_result)) {
         return null;
     }
     $row = mysql_fetch_array($query_result);
     $idx = $row['idx'];
     return Experiment::Lookup($idx);
 }
コード例 #8
0
<?php

/**
 * @author Anne L'Hôte <*****@*****.**>
 */
require_once 'experiment.php';
$oExperimentClass = new Experiment();
?>

<html>
	<head>
		<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
		<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
		<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
		<script type="text/javascript" src="../scripts/experiments.js"></script>
		<script type="text/javascript" src="../../lang/lang.js"></script>
		<link rel="stylesheet" type="text/css" href="../css/experiments.css" />
		<meta charset="utf-8" />
	</head>
	<body>
		<div class="container">
			<div class="row"><h1>Experiment form</h1></div>
			<div class="row"><div class="messages col-sm-9"></div></div>
			<div class="row">
				<form class="form-horizontal form-experiment" role="form">
					<div class="form-group list-experiments">
						<label class="col-sm-2 control-label">Experiment</label>
						<div class="col-sm-5">
							<select class="form-control">
								<option value="0"></option>
								<?php 
コード例 #9
0
ファイル: res.php プロジェクト: AntonBeletsky/YiiBones
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdExp()
 {
     return $this->hasOne(Experiment::className(), ['id_exp' => 'id_exp']);
 }
コード例 #10
0
ファイル: showpool.php プロジェクト: mahyuddin/emulab-stable
# Only known and logged in users can look at experiments.
#
$this_user = CheckLoginOrDie();
$uid = $this_user->uid();
$isadmin = ISADMIN();
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("sortby", PAGEARG_STRING);
if (!isset($sortby)) {
    $sortby = "";
}
PAGEHEADER("Shared Pool");
$experiment = Experiment::LookupByPidEid("emulab-ops", "shared-nodes");
if (!$experiment) {
    $experiment = Experiment::LookupByPidEid("emulab-ops", "shared-node");
}
if (!$experiment) {
    USERERROR("No shared pool experiment!", 1);
}
$pid = $experiment->pid();
$eid = $experiment->eid();
$counts = array();
$nodes = array();
#
# Get the counts per node.
#
$query_result = DBQueryFatal("select phys_nodeid,count(phys_nodeid) as vcount " . "  from reserved as r " . "left join nodes as n on n.node_id=r.node_id " . "where n.node_id!=n.phys_nodeid and " . "      r.sharing_mode is not null " . "group by phys_nodeid");
while ($row = mysql_fetch_array($query_result)) {
    $node_id = $row["phys_nodeid"];
    $count = $row["vcount"];
コード例 #11
0
 $thistag = $row["tag"];
 $exptidx = $row["exptidx"];
 $pid = $row["pid"];
 $eid = $row["eid"];
 $alloc = $row["allocated"];
 $id = 0;
 $slice = "--";
 if (isset($row["released"])) {
     $free = $row["released"];
 } else {
     $free = "&nbsp";
 }
 if (isset($row["history_id"])) {
     $id = $row["history_id"];
 }
 $experiment = Experiment::Lookup($exptidx);
 $experiment_stats = ExperimentStats::Lookup($exptidx);
 if ($experiment_stats && $experiment_stats->slice_uuid()) {
     $url = CreateURL("genihistory", "slice_uuid", $experiment_stats->slice_uuid());
     $slice = "<a href='{$url}'>" . "<img src=\"greenball.gif\" border=0></a>";
 }
 if ($experiment) {
     $expurl = CreateURL("showexp", URLARG_EID, $experiment->idx());
 } else {
     $expurl = CreateURL("showexpstats", "record", $experiment_stats->exptidx());
 }
 if ($id > $max_history_id) {
     $max_history_id = $id;
 }
 $html .= "<tr>";
 if (!$tag) {
コード例 #12
0
 function GetExperiment()
 {
     if ($this->experiment) {
         return $this->experiment;
     }
     if ($this->exptidx()) {
         $this->experiment = Experiment::Lookup($this->exptidx());
     }
     return $this->experiment;
 }
コード例 #13
0
 function LookupExperiment($eid)
 {
     return Experiment::LookupByPidEid($this->pid(), $eid);
 }
コード例 #14
0
ファイル: user_defs.php プロジェクト: mahyuddin/emulab-stable
 function ExperimentList($listify = 1, $group = null)
 {
     $uid_idx = $this->uid_idx();
     $gclause = "";
     # within optional group only.
     if ($group) {
         $pid = $group->pid();
         $gid = $group->gid();
         $gclause = "and pid='{$pid}' and gid='{$gid}'";
     }
     $query_result = DBQueryFatal("select idx from experiments " . "where creator_idx='{$uid_idx}' {$gclause}");
     if (!$listify) {
         return mysql_num_rows($query_result);
     }
     # Else, create a list of the groups.
     $result = array();
     while ($row = mysql_fetch_array($query_result)) {
         $idx = $row["idx"];
         if (!($experiment = Experiment::Lookup($idx))) {
             TBERROR("Group::ExperimentList: " . "Could not load experiment {$idx}!", 1);
         }
         $result[] = $experiment;
     }
     return $result;
 }
コード例 #15
0
ファイル: toggle.php プロジェクト: mahyuddin/emulab-stable
        PAGEARGERROR("Experiment {$pid}/{$eid} is not a valid experiment!");
    }
    $zapurl = CreateURL("showexp", $experiment);
    $experiment->SetLockDown($value);
} elseif ($type == "skipvlans") {
    # Must validate the pid,eid since we allow non-admins to do this.
    if (!TBvalid_pid($pid)) {
        PAGEARGERROR("Invalid characters in {$pid}");
    }
    if (!TBvalid_eid($eid)) {
        PAGEARGERROR("Invalid characters in {$eid}");
    }
    if (!($isadmin || STUDLY() || OPSGUY())) {
        USERERROR("You do not have permission to toggle {$type}!", 1);
    }
    if (!($experiment = Experiment::LookupByPidEid($pid, $eid))) {
        PAGEARGERROR("Experiment {$pid}/{$eid} is not a valid experiment!");
    }
    if (!$isadmin && !TBMinTrust(TBGrpTrust($uid, $pid, $pid), $TBDB_TRUST_LOCALROOT)) {
        USERERROR("You do not have permission to toggle {$type}!", 1);
    }
    $zapurl = CreateURL("showexp", $experiment);
    $experiment->SetSkipVlans($value);
} elseif ($type == "imageglobal" || $type == "imagedoesxen") {
    include "imageid_defs.php";
    # Must validate since we allow non-admins to do this.
    if (!TBvalid_imageid($imageid)) {
        PAGEARGERROR("Invalid characters in {$imageid}");
    }
    if (!($image = Image::Lookup($imageid))) {
        PAGEARGERROR("Image {$image} is not a valid image!");
コード例 #16
0
<?php

/**
 * @author Anne L'Hôte <*****@*****.**>
 * 
 * Called by scripts/experiments.js
 **/
require_once 'experiment.php';
$iExperimentId = $_POST['experiment_id'];
$oExperimentClass = new Experiment();
$oExperimentClass->deleteExperiment($iExperimentId);
コード例 #17
0
    PAGEARGERROR("Must provide one of experiment, instance or template");
}
#
# An instance might be a current or historical. If its a template, use
# the underlying experiment of the template.
#
if (isset($instance)) {
    if ($foo = $instance->GetExperiment()) {
        $experiment = $foo;
    } else {
        $index = $instance->exptidx();
    }
} elseif (isset($template)) {
    $experiment = $template->GetExperiment();
} elseif (isset($index)) {
    $experiment = Experiment::Lookup($index);
}
#
# If we got a current experiment, great. Otherwise we have to lookup
# data for a historical experiment.
#
if (isset($experiment) && $experiment) {
    # Need these below.
    $pid = $experiment->pid();
    $gid = $experiment->gid();
    $eid = $experiment->eid();
    $idx = $experiment->idx();
    $stats = $experiment->GetStats();
    if (!$stats) {
        TBERROR("Could not load stats object for experiment {$pid}/{$eid}", 1);
    }
コード例 #18
0
ファイル: beginexp.php プロジェクト: mahyuddin/emulab-stable
    echo "<blockquote><pre>{$suexec_output}<pre></blockquote>";
    PAGEFOOTER();
    exit;
}
# Display a useful message.
$message = "";
if ($nonsfile) {
    $message = "Since you did not provide an NS script, no nodes have been\n          allocated. You will not be able to modify or swap this experiment,\n          nor do most other neat things you can do with a real experiment.";
} elseif ($exp_preload) {
    $message = "Since you are only pre-loading the experiment, this will typically\n          take less than one minute. If you do not receive email notification\n          within a reasonable amount of time, please contact {$TBMAILADDR}.";
} elseif ($exp_batched) {
    $message = "Batch Mode experiments will be run when enough resources become\n          available. This might happen immediately, or it may take hours\n\t  or days. You will be notified via email when the experiment has\n          been run. If you do not receive email notification within a\n          reasonable amount of time, please contact {$TBMAILADDR}.";
} else {
    $message = "You will be notified via email when the experiment has been fully\n\t  configured and you are able to proceed. This typically takes less\n          than 10 minutes, depending on the number of nodes you have requested.\n          If you do not receive email notification within a reasonable amount\n          of time, please contact {$TBMAILADDR}.";
}
# Map to the actual experiment and show the log.
if ($experiment = Experiment::LookupByPidEid($formfields["exp_pid"], $formfields["exp_id"])) {
    echo $experiment->PageHeader();
    echo "<br>\n";
    echo "<b>Starting experiment configuration!</b> " . $message;
    echo "<br><br>\n";
    STARTLOG($experiment);
} else {
    echo "<br>\n";
    echo "<b>Starting experiment configuration!</b> " . $message;
    echo "<br>\n";
}
#
# Standard Testbed Footer
#
PAGEFOOTER();
コード例 #19
0
 public function add_result()
 {
     $requirements = ['exp_id', 'user_id', 'data'];
     $check = self::check_requirements($requirements);
     if ($check) {
         return Error::make(0, 100, $check);
     }
     $experiment = Experiment::where('exp_id', '=', Input::get('exp_id'))->first();
     if (is_null($experiment)) {
         return Error::make(1, 10);
     }
     $user = User::where('user_id', '=', Input::get('user_id'))->first();
     if (is_null($user)) {
         return Error::make(1, 1);
     }
     if (Input::has('result_id')) {
         $res = Result::where('result_id', '=', Input::get('result_id'))->first();
         if (intval(Input::get('exp_id')) != intval($res->exp_id)) {
             return Error::make(1, 11);
         }
         if (intval(Input::get('user_id')) != intval($res->user_id)) {
             return Error::make(1, 12);
         }
     }
     $columns = json_decode($experiment->specifications, true)["columns"];
     $results = json_decode(Input::get('data'), true);
     foreach ($results as $reading) {
         foreach ($columns as $column) {
             if (array_key_exists($column["title"], $reading)) {
                 if (!is_null($column["subcolumns"]) && sizeof($column["subcolumns"]) > 0) {
                     foreach ($column["subcolumns"] as $subcolumn) {
                         if (!array_key_exists($subcolumn["title"], $reading[$column["title"]])) {
                             return Error::make(101, 101, "Column " . $column["title"] . " has missing subcolumn " . $subcolumn["title"]);
                         }
                     }
                 }
             } else {
                 return Error::make(101, 101, "Missing column " . $column["title"]);
             }
         }
     }
     if (Input::has('result_id')) {
         try {
             Result::where('result_id', '=', intval(Input::get('result_id')))->update(array('data' => json_encode($results)));
             return Error::success("Results successfully updated", array('result_id' => intval(Input::get('result_id'))));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     } else {
         $res = new Result();
         $res->data = json_encode($results);
         $res->user_id = intval(Input::get('user_id'));
         $res->exp_id = intval(Input::get('exp_id'));
         try {
             $res->save();
             return Error::success("Result successfully added!", array('result_id' => $res->id));
         } catch (Exception $e) {
             return Error::make(101, 101, $e->getMessage());
         }
     }
 }
コード例 #20
0
<?php

/**
 * @author Anne L'Hôte <*****@*****.**>
 *
 * Called by scripts/experiments.js
 **/
require_once 'experiment.php';
$iExperimentId = $_POST['experiment_id'];
$sExperimentName = $_POST['experiment_name'];
$bExperimentLoginPhase = $_POST['experiment_login_phase'];
$bExperimentResultsPhase = $_POST['experiment_results_phase'];
$bExperimentGenerateTokens = $_POST['experiment_generate_tokens'];
$bExperimentIsOver = $_POST['experiment_is_over'];
$aExperimentGames = $_POST['experiment_games'];
$oExperimentClass = new Experiment();
$result = $oExperimentClass->saveExperiment($iExperimentId, $sExperimentName, $bExperimentLoginPhase, $bExperimentResultsPhase, $bExperimentGenerateTokens, $bExperimentIsOver, $aExperimentGames);
echo json_encode(['success' => $result]);
コード例 #21
0
 function ExperimentList($listify = 1)
 {
     $pid = $this->pid();
     $gid = $this->gid();
     $query_result = DBQueryFatal("select idx from experiments " . "where pid='{$pid}' and gid='{$gid}'");
     if (!$listify) {
         return mysql_num_rows($query_result);
     }
     # Else, create a list of the groups.
     $result = array();
     while ($row = mysql_fetch_array($query_result)) {
         $idx = $row["idx"];
         if (!($experiment = Experiment::Lookup($idx))) {
             TBERROR("Group::ExperimentList: " . "Could not load experiment {$idx}!", 1);
         }
         $result[] = $experiment;
     }
     return $result;
 }
コード例 #22
0
ファイル: node_defs.php プロジェクト: mahyuddin/emulab-stable
 function Reservation()
 {
     $node_id = $this->node_id();
     $query_result = DBQueryFatal("select pid,eid from reserved " . "where node_id='{$node_id}'");
     if (mysql_num_rows($query_result) == 0) {
         return null;
     }
     $row = mysql_fetch_array($query_result);
     $pid = $row["pid"];
     $eid = $row["eid"];
     return Experiment::LookupByPidEid($pid, $eid);
 }
コード例 #23
0
 function ShowExperiments($user)
 {
     global $TBOPSPID;
     global $TB_EXPT_READINFO;
     $uid = $user->uid();
     $pid = $this->pid();
     $osname = $this->osname();
     #
     # Due to the funny way we handle 'global' images in the emulab-ops
     # project, we have to treat its images specially - namely, we
     # have to make sure there is not an osname in that project, which
     # takes priority over the global ones.
     #
     if ($pid == $TBOPSPID) {
         $query_result = DBQueryFatal("select distinct v.pid, v.eid, e.state " . "     from virt_nodes as v " . "left join os_info as o on " . "     v.osname=o.osname and v.pid=o.pid " . "left join experiments as e on v.pid=e.pid and " . "     v.eid=e.eid " . "where v.osname='{$osname}' and o.osname is NULL " . "order by v.pid, v.eid, e.state");
     } else {
         $query_result = DBQueryFatal("select distinct v.pid, v.eid, e.state " . "  from virt_nodes as v " . "left join experiments as e " . "     on v.pid=e.pid and v.eid=e.eid " . "where v.pid='{$pid}' and v.osname='{$osname}' " . "order by v.pid, v.eid, e.state");
     }
     if (mysql_num_rows($query_result) == 0) {
         echo "<h4 align='center'>No experiments are using this OS</h3>";
     } else {
         $other_exps = 0;
         echo "<h3 align='center'>Experiments using this OS</h3>\n";
         echo "<table align=center border=1>\n";
         echo "  <tr> \n\t\t        <th>PID</th>\n   \t\t        <th>EID</th>\n\t\t        <th>State</th>\n\t\t    </tr>\n";
         while ($row = mysql_fetch_array($query_result)) {
             $pid = $row[0];
             $eid = $row[1];
             $state = $row[2];
             #
             # Gotta make sure that the user actually has the right to
             # see this experiment - summarize all the experiments that
             # he/she cannot see at the bottom
             #
             if (!($experiment = Experiment::LookupByPidEid($pid, $eid))) {
                 continue;
             }
             if (!$experiment->AccessCheck($user, $TB_EXPT_READINFO)) {
                 $other_exps++;
                 continue;
             }
             $showexp_url = CreateURL("showexp", $experiment);
             echo "<tr>\n";
             echo "  <td>{$pid}</td>\n";
             echo "  <td><a href='{$showexp_url}'>{$eid}</td>\n";
             echo "  <td>{$state}</td>\n";
             echo "</tr>\n";
         }
         if ($other_exps) {
             echo "<tr><td colspan=3>\n                        {$other_exps} experiments in other projects</td></tr>\n";
         }
         echo "</table>\n";
     }
 }
コード例 #24
0
ファイル: url_defs.php プロジェクト: mahyuddin/emulab-stable
function VerifyPageArguments($argspec, $required)
{
    global $drewheader;
    if ($drewheader) {
        trigger_error("PAGEHEADER called before VerifyPageArguments " . "(called by RequiredPageArguments or OptionalPageArguments). " . "Won't be able to return proper HTTP status code on Error " . "in " . $_SERVER['SCRIPT_FILENAME'] . ",", E_USER_WARNING);
    }
    $result = array();
    while ($argspec and count($argspec) > 1) {
        $name = array_shift($argspec);
        $type = array_shift($argspec);
        $yep = 0;
        unset($object);
        switch ($type) {
            case PAGEARG_EXPERIMENT:
                if (isset($_REQUEST[URL_EXPERIMENT])) {
                    $idx = $_REQUEST[URL_EXPERIMENT];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_EXPERIMENT, $idx)) {
                        $object = Experiment::Lookup($idx);
                    }
                } elseif (isset($_REQUEST[URL_EXPTIDX])) {
                    $idx = $_REQUEST[URL_EXPTIDX];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_EXPERIMENT, $idx)) {
                        $object = Experiment::Lookup($idx);
                    }
                } elseif (isset($_REQUEST[URL_PID]) && isset($_REQUEST[URL_EID])) {
                    $pid = $_REQUEST[URL_PID];
                    $eid = $_REQUEST[URL_EID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_PID, $pid) && ValidateArgument(PAGEARG_EID, $eid)) {
                        $object = Experiment::LookupByPidEid($pid, $eid);
                    }
                }
                break;
            case PAGEARG_TEMPLATE:
                if (isset($_REQUEST[URL_GUID]) && isset($_REQUEST[URL_VERS])) {
                    $guid = $_REQUEST[URL_GUID];
                    $vers = $_REQUEST[URL_VERS];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_GUID, $guid) && ValidateArgument(PAGEARG_VERS, $vers)) {
                        $object = Template::Lookup($guid, $vers);
                    }
                } elseif (isset($_REQUEST[URL_TEMPLATE])) {
                    $guidvers = $_REQUEST[URL_TEMPLATE];
                    $yep = 1;
                    if (preg_match("/^([\\d]+)\\/([\\d]+)\$/", $guidvers, $matches)) {
                        $guid = $matches[1];
                        $vers = $matches[2];
                        $object = Template::Lookup($guid, $vers);
                    } else {
                        PAGEARGERROR("Invalid argument for '{$type}': {$guidvers}");
                    }
                }
                break;
            case PAGEARG_INSTANCE:
                if (isset($_REQUEST[URL_INSTANCE])) {
                    $idx = $_REQUEST[URL_INSTANCE];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_INSTANCE, $idx)) {
                        $object = TemplateInstance::LookupByExptidx($idx);
                    }
                }
                break;
            case PAGEARG_METADATA:
                if (isset($_REQUEST[URL_METADATA])) {
                    $guidvers = $_REQUEST[URL_METADATA];
                    $yep = 1;
                    if (preg_match("/^([\\d]+)\\/([\\d]+)\$/", $guidvers, $matches)) {
                        $guid = $matches[1];
                        $vers = $matches[2];
                        $object = TemplateMetadata::Lookup($guid, $vers);
                    } else {
                        PAGEARGERROR("Invalid argument for '{$type}': {$guidvers}");
                    }
                }
                break;
            case PAGEARG_PROJECT:
                if (isset($_REQUEST[URL_PROJECT])) {
                    $idx = $_REQUEST[URL_PROJECT];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_PROJECT, $idx)) {
                        $object = Project::Lookup($idx);
                    }
                } elseif (isset($_REQUEST[URL_PID])) {
                    $pid = $_REQUEST[URL_PID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_PID, $pid)) {
                        $object = Project::Lookup($pid);
                    }
                }
                break;
            case PAGEARG_GROUP:
                if (isset($_REQUEST[URL_GROUP])) {
                    $idx = $_REQUEST[URL_GROUP];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_GROUP, $idx)) {
                        $object = Group::Lookup($idx);
                    }
                } elseif (isset($_REQUEST[URL_PID]) && isset($_REQUEST[URL_GID])) {
                    $pid = $_REQUEST[URL_PID];
                    $gid = $_REQUEST[URL_GID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_PID, $pid) && ValidateArgument(PAGEARG_GID, $gid)) {
                        $object = Group::LookupByPidGid($pid, $gid);
                    }
                }
                break;
            case PAGEARG_NODE:
                if (isset($_REQUEST[URL_NODE])) {
                    $idx = $_REQUEST[URL_NODE];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_NODE, $idx)) {
                        $object = Node::Lookup($idx);
                    }
                } elseif (isset($_REQUEST[URL_NODEID])) {
                    $nodeid = $_REQUEST[URL_NODEID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_NODEID, $nodeid)) {
                        $object = Node::Lookup($nodeid);
                    }
                } elseif (isset($_REQUEST[URL_NODEID_ALT])) {
                    $nodeid = $_REQUEST[URL_NODEID_ALT];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_NODEID, $nodeid)) {
                        $object = Node::Lookup($nodeid);
                    }
                }
                break;
            case PAGEARG_USER:
                if (isset($_REQUEST[URL_USER])) {
                    $idx = $_REQUEST[URL_USER];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_USER, $idx)) {
                        $object = User::Lookup($idx);
                    }
                } elseif (isset($_REQUEST[URL_UID])) {
                    $uid = $_REQUEST[URL_UID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_UID, $uid)) {
                        $object = User::Lookup($uid);
                    }
                }
                break;
            case PAGEARG_IMAGE:
                if (isset($_REQUEST[URL_IMAGEID])) {
                    $imageid = $_REQUEST[URL_IMAGEID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_IMAGE, $imageid)) {
                        $object = Image::Lookup($imageid);
                    }
                } elseif (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") {
                    $imageid = $_REQUEST[$name];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_IMAGE, $imageid)) {
                        $object = Image::Lookup($imageid);
                    }
                }
                break;
            case PAGEARG_OSINFO:
                if (isset($_REQUEST[URL_OSID])) {
                    $osid = $_REQUEST[URL_OSID];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_OSINFO, $osid)) {
                        $object = OSinfo::Lookup($osid);
                    }
                }
                break;
            case PAGEARG_BOOLEAN:
                if (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") {
                    $object = $_REQUEST[$name];
                    $yep = 1;
                    if (strcasecmp("{$object}", "yes") == 0 || strcasecmp("{$object}", "1") == 0 || strcasecmp("{$object}", "true") == 0 || strcasecmp("{$object}", "on") == 0) {
                        $object = True;
                    } elseif (strcasecmp("{$object}", "no") == 0 || strcasecmp("{$object}", "0") == 0 || strcasecmp("{$object}", "false") == 0 || strcasecmp("{$object}", "off") == 0) {
                        $object = False;
                    }
                }
                break;
            case PAGEARG_INTEGER:
            case PAGEARG_NUMERIC:
            case PAGEARG_ARRAY:
                if (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") {
                    $object = $_REQUEST[$name];
                    $yep = 1;
                    if (!ValidateArgument($type, $object)) {
                        unset($object);
                    }
                }
                break;
            case PAGEARG_ANYTHING:
                if (isset($_REQUEST[$name])) {
                    $object = $_REQUEST[$name];
                    $yep = 1;
                    # Anything allowed, caller BETTER check it.
                }
                break;
            case PAGEARG_ALPHALIST:
                if (isset($_REQUEST[$name])) {
                    $object = $_REQUEST[$name];
                    if (!preg_match("/^[\\d\\w\\-\\ \\,]+\$/", $object)) {
                        unset($object);
                    } else {
                        $object = preg_split("/[\\,\\;]+\\s*/", $_REQUEST[$name]);
                    }
                }
                break;
            case PAGEARG_STRING:
            default:
                if (isset($_REQUEST[$name])) {
                    $object = $_REQUEST[$name];
                    $yep = 1;
                    # Pages never get arguments with special chars. Check.
                    if (preg_match("/[\\'\"]/", $object)) {
                        $object = htmlspecialchars($object);
                        PAGEARGERROR("Invalid characters in '{$name}': {$object}");
                    }
                }
                break;
            case PAGEARG_PASSWORD:
            default:
                if (isset($_REQUEST[$name])) {
                    $object = $_REQUEST[$name];
                    $yep = 1;
                    # Only printable chars.
                    if (!preg_match("/^[ -~]+\$/", $object)) {
                        PAGEARGERROR("Invalid characters in '{$name}'");
                    }
                }
                break;
            case PAGEARG_LOGFILE:
                if (isset($_REQUEST[URL_LOGFILE])) {
                    $logid = $_REQUEST[URL_LOGFILE];
                    $yep = 1;
                    if (ValidateArgument(PAGEARG_LOGFILE, $logid)) {
                        $object = Logfile::Lookup($logid);
                    }
                }
                break;
        }
        if (isset($object)) {
            $result[$name] = $object;
            $GLOBALS[$name] = $object;
        } elseif ($yep) {
            #
            # Value supplied but could not be mapped to object.
            # Lets make that clear in the error message.
            #
            USERERROR("Could not map page arguments to '{$name}'", 1);
        } elseif ($required) {
            PAGEARGERROR("Must provide '{$name}' page argument");
        } else {
            unset($GLOBALS[$name]);
        }
    }
    return $result;
}
コード例 #25
0
<?php

/**
 * @author Anne L'Hôte <*****@*****.**>
 * 
 * Called by scripts/experiments.js
 **/
require_once 'experiment.php';
$iExperimentId = $_POST['experiment_id'];
$oExperimentClass = new Experiment();
$oExperiment = $oExperimentClass->getExperiment($iExperimentId);
echo json_encode($oExperiment);
コード例 #26
0
    }
    $which = $type == "cm" ? "Component Manager" : ($type == "sa" ? "Slice Authority" : "Clearing House");
    if (!$slicelist || !count($slicelist)) {
        continue;
    }
    # The form attributes:
    $table = array('#id' => $type, '#title' => $which, '#sortable' => 1, '#headings' => array("idx" => "ID", "hrn" => "HRN", "created" => "Created", "expires" => "Expires"));
    $rows = array();
    foreach ($slicelist as $slice) {
        $slice_idx = $slice->idx();
        $slice_hrn = $slice->hrn();
        $created = $slice->created();
        $expires = $slice->expires();
        $url = CreateURL("showslice", "showtype", $type, "slice_idx", $slice_idx);
        $href = "<a href='{$url}'>{$slice_hrn}</a>";
        $experiment = Experiment::LookupByUUID($slice->uuid());
        if ($experiment) {
            $eid = $experiment->eid();
            $expurl = CreateURL("showexp", $experiment);
            $href = "{$href} (<a href='{$expurl}'>{$eid}</a>)";
        }
        $rows[$slice_idx] = array("idx" => $slice_idx, "hrn" => $href, "created" => $created, "expires" => $expires);
    }
    list($html, $button) = TableRender($table, $rows);
    echo $html;
}
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
コード例 #27
0
} elseif (!isset($formfields)) {
    PAGEARGERROR();
}
#
# Okay, validate form arguments.
#
$errors = array();
$eid = "";
#
# EID:
#
if (!isset($formfields["eid"]) || $formfields["eid"] == "") {
    $errors["ID"] = "Missing Field";
} elseif (!TBvalid_eid($formfields["eid"])) {
    $errors["ID"] = TBFieldErrorString();
} elseif (Experiment::Lookup($pid, $formfields["eid"])) {
    $errors["ID"] = "Already in use";
} else {
    $eid = $formfields["eid"];
}
# Set up command options
$command_options = "";
#
# Swappable
#
if (!isset($formfields["exp_swappable"]) || strcmp($formfields["exp_swappable"], "1")) {
    $formfields["exp_swappable"] = 0;
    if (!isset($formfields["exp_noswap_reason"]) || !strcmp($formfields["exp_noswap_reason"], "")) {
        if (!$isadmin) {
            $errors["Not Swappable"] = "No justification provided";
        } else {