Example #1
0
function ajoutJustificationsParDefaut() {
    $justifications = new AbsenceEleveJustification();
    $justifications->setNom("Certificat médical");
    $justifications->setCommentaire("Une justification établie par une autorité médicale");
    if (AbsenceEleveJustificationQuery::create()->filterByNom($justifications->getNom())->find()->isEmpty()) {
	$justifications->save();
    }

    $justifications = new AbsenceEleveJustification();
    $justifications->setNom("Courrier familial");
    $justifications->setCommentaire("Justification par courrier de la famille");
    if (AbsenceEleveJustificationQuery::create()->filterByNom($justifications->getNom())->find()->isEmpty()) {
	$justifications->save();
    }

    $justifications = new AbsenceEleveJustification();
    $justifications->setNom("Justificatif d'une administration publique");
    $justifications->setCommentaire("Justification émise par une administration publique");
    if (AbsenceEleveJustificationQuery::create()->filterByNom($justifications->getNom())->find()->isEmpty()) {
	$justifications->save();
    }
}
	/**
	 * Declares an association between this object and a AbsenceEleveJustification object.
	 *
	 * @param      AbsenceEleveJustification $v
	 * @return     AbsenceEleveTraitement The current object (for fluent API support)
	 * @throws     PropelException
	 */
	public function setAbsenceEleveJustification(AbsenceEleveJustification $v = null)
	{
		if ($v === null) {
			$this->setAJustificationId(NULL);
		} else {
			$this->setAJustificationId($v->getId());
		}

		$this->aAbsenceEleveJustification = $v;

		// Add binding for other direction of this n:n relationship.
		// If this object has already been added to the AbsenceEleveJustification object, it will not be re-added.
		if ($v !== null) {
			$v->addAbsenceEleveTraitement($this);
		}

		return $this;
	}
	/**
	 * Exchange the rank of the object with the one passed as argument, and saves both objects
	 *
	 * @param     AbsenceEleveJustification $object
	 * @param     PropelPDO $con optional connection
	 *
	 * @return    AbsenceEleveJustification the current object
	 *
	 * @throws Exception if the database cannot execute the two updates
	 */
	public function swapWith($object, PropelPDO $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(AbsenceEleveJustificationPeer::DATABASE_NAME);
		}
		$con->beginTransaction();
		try {
			$oldRank = $this->getSortableRank();
			$newRank = $object->getSortableRank();
			$this->setSortableRank($newRank);
			$this->save($con);
			$object->setSortableRank($oldRank);
			$object->save($con);
			$con->commit();
	
			return $this;
		} catch (Exception $e) {
			$con->rollback();
			throw $e;
		}
	}
	/**
	 * Exclude object from result
	 *
	 * @param     AbsenceEleveJustification $absenceEleveJustification Object to remove from the list of results
	 *
	 * @return    AbsenceEleveJustificationQuery The current query, for fluid interface
	 */
	public function prune($absenceEleveJustification = null)
	{
		if ($absenceEleveJustification) {
			$this->addUsingAlias(AbsenceEleveJustificationPeer::ID, $absenceEleveJustification->getId(), Criteria::NOT_EQUAL);
		}

		return $this;
	}
	/**
	 * Filter the query by a related AbsenceEleveJustification object
	 *
	 * @param     AbsenceEleveJustification|PropelCollection $absenceEleveJustification The related object(s) to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    AbsenceEleveTraitementQuery The current query, for fluid interface
	 */
	public function filterByAbsenceEleveJustification($absenceEleveJustification, $comparison = null)
	{
		if ($absenceEleveJustification instanceof AbsenceEleveJustification) {
			return $this
				->addUsingAlias(AbsenceEleveTraitementPeer::A_JUSTIFICATION_ID, $absenceEleveJustification->getId(), $comparison);
		} elseif ($absenceEleveJustification instanceof PropelCollection) {
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
			return $this
				->addUsingAlias(AbsenceEleveTraitementPeer::A_JUSTIFICATION_ID, $absenceEleveJustification->toKeyValue('PrimaryKey', 'Id'), $comparison);
		} else {
			throw new PropelException('filterByAbsenceEleveJustification() only accepts arguments of type AbsenceEleveJustification or PropelCollection');
		}
	}
    }
} elseif ($action == 'descendre') {
	check_token();
    if ($justification != null) {
	$justification->moveDown();
    }
} elseif ($action == 'ajouterdefaut') {
	check_token();
    //include("function.php");
    ajoutJustificationsParDefaut();
} else {
    if ($nom != '') {
		check_token();
		$justification = AbsenceEleveJustificationQuery::create()->findPk($id);
		if ($justification == null) {
			$justification = new AbsenceEleveJustification();
		}
		$justification->setNom(stripslashes($nom));
		$justification->setCommentaire(stripslashes($commentaire));
		$justification->save();
    }
}

if(isset($_GET['corriger'])) {
	check_token();

	$table="a_justifications";

	$sql="SELECT * FROM $table ORDER BY sortable_rank, nom;";
	//echo "$sql<br />";
	$res=mysqli_query($GLOBALS["mysqli"], $sql);