Commit 2920114d authored by Anatole Rakotoson's avatar Anatole Rakotoson
Browse files

Merge remote-tracking branch 'origin/qa' into qa

parents c3c53690 a83c5202
<?php
/**
* PaymentController.php
*
*
* @author: Dady Christon <devchriston@gmail.com>
* Date: 26/02/2021
*/
class PaymentController extends CommunecterController {
protected function beforeAction($action) {
return parent::beforeAction($action);
}
public function actionPay(){
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_t7D34dypCf67SrtJDb4QN5xNETpB3a");
# $mollie->setAccessToken("Here is token if needed");
$orderId = time();
$protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
$hostname = $_SERVER['HTTP_HOST'];
$path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
$payment = $mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => $_POST["amount"]["value"]
],
"description" => $_POST["description"],
"method" => "creditcard",
"redirectUrl" => "{$protocol}://{$hostname}{$path}/check/?order_id={$orderId}&form={$_POST['form']}&page={$_POST['page']}",
"webhookUrl" => "{$protocol}://{$hostname}{$path}",
"metadata" => [
"order_id" => $orderId,
],
]);
# insert payment infos to database
PHDB::insert("payments",
array(
'payment' => array(
'id' => $payment->id,
'currency' => "EUR",
'value' => $_POST["amount"]["value"],
'description' => $_POST["description"],
'nbPart' => $_POST["nbPart"],
'isPaid' => false
),
'user' => $_SESSION["userId"],
'source' => array('form' => $_POST["form"]),
'orderId' => "$orderId"
)
);
return Rest::json(array('url' => $payment->getCheckoutUrl()));
}
# Check if payment is paid
public function actionCheck($order_id, $form, $page){
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_t7D34dypCf67SrtJDb4QN5xNETpB3a");
# $mollie->setAccessToken("Here is token if needed"); 0340287138
$p = PHDB::findOne("payments", array('orderId' => "$order_id"));
if(isset($p["payment"]["id"])){
$payment = $mollie->payments->get($p["payment"]["id"]);
if ($payment->isPaid()){
$res = array('isPaid' => true);
PHDB::update("payments", array('orderId' => "$order_id"), array('$set' => array('payment.isPaid' => true)));
PHDB::update("answers", array('user' => $_SESSION["userId"], 'form' => "$form"), array('$set' => array('answers.isPaid' => true)));
}else{
$res = array('isPaid' => false);
}
}else{
$res = array('isPaid' => false);
}
return $this->redirect("$page");
}
public function actionInvoice($id, $slug, $user=null, $form=null) {
$doc = array();
$orga = PHDB::findOne("organizations", array('slug' => $slug ));
$orga["siret"] = "51338183000019";
$payment = PHDB::findOne("payments", array('user' => $user, 'source.form'=> $form));
$customer = PHDB::findOneById("citoyens", $user);
$params = array(
'organization' => $orga,
'associe' => $customer,
'payment' => $payment,
'currency' => "€"
);
$tpl = $this->renderPartial('application.views.pdf.factureOpenAtlas',
$params, true);
$doc["html"] = $tpl;
Pdf::createPdf($doc);
//echo $tpl;
}
}
<?php
$ids = explode(".", $answerPath);
$inpClass = "saveOneByOne";
if($answer){
$myProjects = PHDB::find("projects", array("creator"=>Yii::app()->session["userId"]));
$prj_ids = [];
if($mode=="w"){
$projs = $myProjects;
}else{
if(isset($answer[$ids[0]][$ids[1]]["projets"])){
foreach ($answer[$ids[0]][$ids[1]]["projets"] as $kp => $vpbool) {
array_push($prj_ids, $kp);
}
}
$projs = PHDB::findByIds("projects", $prj_ids);
}
?>
<div class="form-group">
<?php
$editBtnL="";
if($answer["user"]==Yii::app()->session["userId"]){
$editBtnL = " <a href='javascript:;'
data-id='".$answer["_id"]."'
data-collection='".Form::ANSWER_COLLECTION."'
data-path='".$answerPath."'
class='add btn btn-default' onclick='dyFObj.openForm(`project`);'>
<i class='fa fa-plus'></i>
Ajouter un projet
</a>";
}
?>
<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">
<?php echo $label.$editQuestionBtn.$editBtnL?>
</h4>
<?php echo $info ?>
<!--h5>prjnisations :</h5-->
<?php if(isset($projs)){
foreach ($projs as $keyp => $prj) {
echo '<div class="col-md-6 col-sm-12">';
$value = "";
if(isset($answer[$ids[0]][$ids[1]]["projets"])){
if(array_key_exists("$keyp", $answer[$ids[0]][$ids[1]]["projets"])){
$value = "checked";
}
}
?>
<div class="form-check list-group-item">
&nbsp; &nbsp;
<?php if($mode=="w"){ ?>
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?= $keyp ?>" data-form='<?php echo $form["id"] ?>.projets' name="projets" <?php echo $value ?> > &nbsp; &nbsp;
<?php } ?>
<img src="<?= (isset($prj["profilImageUrl"]))?$prj["profilImageUrl"]:Yii::app()->getModule("co2")->assetsUrl.'/images/thumbnail-default.jpg' ?>" height="40" class="img-rounded" alt="">
&nbsp; &nbsp; <?= $prj["name"]; ?>
<br/>
</div>
<?php
echo "</div>";
}
}
?>
</div>
<script></script>
<?php } else {
//echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>";
} ?>
\ No newline at end of file
<?php
$ids = explode(".", $answerPath);
if(isset(Yii::app()->session["userId"])){
$data = PHDB::findByIds("citoyens", [Yii::app()->session["userId"]] ,["links.follows", "links.memberOf"]);
$follows_ids = array();
$memberOf_ids = array();
if(isset(Yii::app()->session["userId"])){
$data = PHDB::findByIds("citoyens", [$answer["user"]] ,["links.follows", "links.memberOf"]);
$follows_ids = array();
$memberOf_ids = array();
$links1 = [];
if($mode=="w"){
if(isset($data[Yii::app()->session["userId"]]["links"]["follows"])){
$links1 = $data[Yii::app()->session["userId"]]["links"]["follows"];
foreach ($links1 as $key => $value) {
array_push($follows_ids, $key);
}
$friends = PHDB::findByIds("citoyens", $follows_ids ,["name", "profilImageUrl"]);
}
}else{
if(isset($answer[$ids[0]][$ids[1]]["friends"])){
$links1 = $answer[$ids[0]][$ids[1]]["friends"];
}
}
foreach ($links1 as $key => $value) {
array_push($follows_ids, $key);
}
$friends = PHDB::findByIds("citoyens", $follows_ids ,["name", "profilImageUrl"]);
$links2 = [];
if($mode=="w"){
if(isset($data[Yii::app()->session["userId"]]["links"]["memberOf"])){
$links2 = $data[Yii::app()->session["userId"]]["links"]["memberOf"];
foreach ($links2 as $key => $value) {
array_push($memberOf_ids, $key);
}
$organizations = PHDB::findByIds("organizations", $memberOf_ids ,["name", "profilImageUrl"]);
}
}else{
if(isset($answer[$ids[0]][$ids[1]]["entreprises"])){
$links2 = $answer[$ids[0]][$ids[1]]["entreprises"];
}
}
foreach ($links2 as $key => $value) {
array_push($memberOf_ids, $key);
}
$organizations = PHDB::findByIds("organizations", $memberOf_ids ,["name", "profilImageUrl"]);
}
?>
<?php $inpClass = "saveOneByOne"; ?>
......@@ -33,18 +54,21 @@
<div class="col-md-6 col-sm-12">
<h5>Citoyens :</h5>
<?php if(isset($friends)) {
foreach ($friends as $key => $friend) {
$value = "";
if(!empty($answer) && isset($answer["answers"]["friends"][$key]) && $answer["answers"]["friends"][$key]){
$value = "checked";
foreach ($friends as $keyf => $friend) {
$valueId = "";
if(isset($answer[$ids[0]][$ids[1]]["friends"])){
if(array_key_exists("$keyf", $answer[$ids[0]][$ids[1]]["friends"])){
$valueId = "checked";
}
}
?>
<div class="form-check list-group-item">
&nbsp; &nbsp;
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?= $key ?>" data-form='friends' name="friends" <?php echo $value ?> >
&nbsp; &nbsp;
<?php if($mode=="w"){ ?>
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?= $keyf ?>" data-form='<?php echo $form["id"] ?>.friends' name="friends" <?php echo $valueId ?> > &nbsp; &nbsp;
<?php } ?>
<img src="<?= (isset($friend["profilImageUrl"]))?$friend["profilImageUrl"]:Yii::app()->getModule("co2")->assetsUrl.'/images/thumb/default_citoyens.png' ?>" height="40" class="img-rounded" alt="">
&nbsp; &nbsp; <?= $friend["name"]; ?>
<br/>
......@@ -56,18 +80,20 @@
<div class="col-md-6 col-sm-12">
<h5>Organisations :</h5>
<?php if(isset($organizations)) {
foreach ($organizations as $key => $orga) {
$value = "";
if(!empty($answer) && isset($answer["answers"]["entreprises"][$key]) && $answer["answers"]["entreprises"][$key]){
$value = "checked";
foreach ($organizations as $keyo => $orga) {
$valueOrgId = "";
if(isset($answer[$ids[0]][$ids[1]]["entreprises"])){
if(array_key_exists("$keyo", $answer[$ids[0]][$ids[1]]["entreprises"])){
$valueOrgId = "checked";
}
}
?>
<div class="form-check list-group-item">
&nbsp; &nbsp;
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?= $key ?>" data-form='entreprises' name="entreprises" <?php echo $value ?> >
&nbsp; &nbsp;
<?php if($mode=="w"){ ?>
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?= $keyo ?>" data-form='<?php echo $form["id"] ?>.entreprises' name="entreprises" <?php echo $valueOrgId ?> > &nbsp; &nbsp;
<?php } ?>
<img src="<?= (isset($orga["profilImageUrl"]))?$orga["profilImageUrl"]:Yii::app()->getModule("co2")->assetsUrl.'/images/thumbnail-default.jpg' ?>" height="40" class="img-rounded" alt="">
&nbsp; &nbsp; <?= $orga["name"]; ?>
<br/>
......
<?php if($answer){
$myProjects = PHDB::find("projects", array("source.key"=>$this->costum["slug"], "creator"=>Yii::app()->session["userId"]))
?>
<div class="form-group">
<?php
$i = 0;
$show = true;
if (isset($answers)) {
foreach ($answers as $q => $a) {
if (isset($answers)) {
$i++;
}
}
}
if(isset($this->costum["form"]["params"][$kunik]['num_row']) and $this->costum["form"]["params"][$kunik]['num_row'] == "0" and isset($this->costum["form"]["params"][$kunik]["nbmax"]) and ((int)$this->costum["form"]["params"][$kunik]["nbmax"]) <= $i){
$show = false;
}
$editBtnL="";
if($show){
$editBtnL = " <a href='javascript:;'
data-id='".$answer["_id"]."'
data-collection='".Form::ANSWER_COLLECTION."'
data-path='".$answerPath."'
class='add btn btn-default' onclick='dyFObj.openForm(`project`);'>
<i class='fa fa-plus'></i>
Ajouter un projet
</a>";
}
$paramsData = [
"nbmax" => "2", "num_row" => ["limité","illimité"]
];
if( isset($this->costum["form"]["params"][$kunik]["nbmax"]) )
$paramsData["nbmax"] = $this->costum["form"]["params"][$kunik]["nbmax"];
if( isset($this->costum["form"]["params"][$kunik]["limited"]) )
$paramsData["num_row"] = $this->costum["form"]["params"][$kunik]["num_row"];
$properties = [
"projectName" => [
"label" => "Titre du projet",
"placeholder" => "",
"inputType" => "text",
"rules" => [ "required" => true ]
],
"projectDescription" => [
"label" => "Description du projet",
"placeholder" => "",
"inputType" => "textarea",
"rules" => [ "required" => true ]
],
"besoinCollaborateur" => [
"label" => "En recheche de collaborateurs",
"placeholder" => "",
"inputType" => "tpls.forms.cplx.multiCheck"
],
"attachement" => [
"label" => "Attachement",
"placeholder" => "Fichier attachement",
"inputType" => "uploader"
]
];
?>
<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">
<?php echo $label.$editQuestionBtn.$editBtnL?>
</h4>
<?php echo $info ?>
<style>
.s19{list-style: none;}
.s19 li:before{
content: '\f0a9';
margin-right: 15px;
font-family: FontAwesome;
color: #d9534f;
}
</style>
<ol class="s19">
<?php
if(isset($myProjects)){
foreach ($myProjects as $q => $a) {
?>
<li>
<?php echo $a["name"] ?>
<span class="pull-right">
<?php
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"canEdit"=>($canEdit||Yii::app()->session["userId"] == $answer["user"]),
"id" => $answer["_id"],
"collection" => Form::ANSWER_COLLECTION,
"q" => $q,
"path" => "answers.".$kunik.".".$q,
"keyTpl"=>$kunik
] ); ?>
<a
href="javascript:;"
class="btn btn-xs btn-primary openAnswersComment"
onclick="commentObj.openPreview(
'answers',
'<?php echo $answer["_id"]?>',
'<?php echo $answer["_id"].$key.$q ?>',
'<?php echo @$a['step'] ?>')"
>
<?php echo PHDB::count(Comment::COLLECTION,
array(
"contextId"=>$answer["_id"],
"contextType"=>"projects",
"path"=>$answer["_id"].$key.$q
)
)
?>
<i class='fa fa-commenting'></i>
</a>
</span>
</li>
<?php
}
}
?>
</ol>
</div>
<script type="text/javascript">
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;
$(document).ready(function() {
sectionDyf.<?php echo $kunik ?>modal = {
"jsonSchema" : {
"title" : "Déclaration de projet",
"icon" : "fa-money",
"text" : "De projet que vous avez réalisé ou aimerez faire",
"properties" : <?php echo json_encode( $properties ); ?>,
save : function () {
var today = new Date();
tplCtx.value = { date : today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear() };
$.each( sectionDyf.<?php echo $kunik ?>modal.jsonSchema.properties , function(k,val) {
tplCtx.value[k] = $("#"+k).val();
});
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").html(`
<div class='text-center'>
<i class='fa fa-spin fa-spinner'></i>
</div>`);//$("#ajax-modal").modal('hide');
location.reload();
} );
}
}
}
};
mylog.log("render","/modules/costum/views/tpls/forms/<?php echo $kunik ?>.php");
//adds a line into answer
$(".add<?php echo $kunik ?>").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path")+((notNull(<?php echo $kunik ?>Data) ? <?php echo $kunik ?>Data.length : "0"));
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>modal);
});
$(".edit<?php echo $kunik ?>").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>modal,null, <?php echo $kunik ?>Data[$(this).data("key")]);
});
$(".edit<?php echo $kunik ?>Params").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
//if no params config on the element.costum.form.params.<?php echo $kunik ?>
//then we load default values available in forms.inputs.<?php echo $kunik ?>xxx.params
//mylog.log(".editParams",sectionDyf.<?php echo $kunik ?>Params,calData);
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>Params,null, sectionDyf.<?php echo $kunik ?>ParamsData);
});
});
</script>
<?php } else {
//echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>";
} ?>
\ No newline at end of file
......@@ -30,11 +30,13 @@
<br>
<div class="form-group">
<input type="text" id="<?= $key ?>" data-form="<?= $form["id"]?>" value="<?php echo $name ?>" class="form-control saveOneByOne">
<input type="text" id="<?= $key ?>" data-form="<?= $form["id"]?>" value="<?php echo $name ?>" class="form-control saveOneByOne" required>
</div>
</div>
<script type="text/javascript">
$("#<?= $key ?>").blur();
$(document).ready(function(){
let kunik = "<?= $kunik ?>";
......
<?php if($answer){
?>
<?php if($answer){ ?>
<div class="form-group">
<?php
<?php
$i = 0;
$show = true;
$show = ($answer["user"]==Yii::app()->session["userId"]);
if (isset($answers)) {
foreach ($answers as $q => $a) {
if (isset($answers)) {
......@@ -14,12 +13,14 @@
if(isset($this->costum["form"]["params"][$kunik]['num_row']) and $this->costum["form"]["params"][$kunik]['num_row'] == "0" and isset($this->costum["form"]["params"][$kunik]["nbmax"]) and ((int)$this->costum["form"]["params"][$kunik]["nbmax"]) <= $i){
$show = false;
}
$editBtnL="";
if($show){
$editBtnL = ($canEdit === true) ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter un élément </a>" : "";
}
$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$el["_id"]."' data-collection='".$this->costum["contextType"]."' data-path='costum.form.params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$editParamsBtn = ($canEdit && $answer["user"]==Yii::app()->session["userId"]) ? " <a href='javascript:;' data-id='".$el["_id"]."' data-collection='".$this->costum["contextType"]."' data-path='costum.form.params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$paramsData = [
"nbmax" => "2", "num_row" => ["limité","illimité"]
......@@ -40,45 +41,50 @@
];
?>
<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?>
<style>
.s19{list-style: none;}
.s19 li:before{
content: '\f0a9';
margin-right: 15px;