Ejemplo n.º 1
0
 protected function setInfoWoocommerce()
 {
     include_once PLUGIN_PATH_SHIPWORKSWORDPRESS . 'functions/woocommerce/functionsWoocommerce.php';
     // Pour les attributs qu'on rentre à partir de Products -> attributes, quand le slug est custom un préfix pa_ est ajouté devant le nom
     if (strlen($this->name) > 3 && substr($this->name, 0, 3) == 'pa_') {
         $this->name = substr($this->name, 3, strlen($this->name) - 1);
         $this->value = ucfirst(getAttributeValue($this->value));
     }
     // Les majuscules
     $this->name = ucfirst($this->name);
     $this->value = ucfirst($this->value);
 }
function &getNodeById(&$node, $id)
{
    $nodeid = getAttributeValue('ID', $node->attributes());
    if ($nodeid == $id) {
        return $node;
    }
    if ($node->type == XML_ELEMENT_NODE) {
        //print ($indent . $node->tagname . "\n");
        $kids = $node->children();
        $nkids = count($kids);
        if ($nkids > 0) {
            for ($i = 0; $i < $nkids; $i++) {
                $nn = getNodeById($kids[$i], $id);
                if ($nn != null) {
                    return $nn;
                }
            }
        }
    }
    return null;
}
function checkconfield($value)
{
    global $surveyid, $thissurvey, $qattributes;
    $fieldisdisplayed = true;
    if (!is_array($thissurvey)) {
        $local_thissurvey = getSurveyInfo($surveyid);
    } else {
        $local_thissurvey = $thissurvey;
    }
    // we know the true fieldname $value (for instance SGQA for each checkboxes)
    // and we want to compare it to the values stored in $_SESSION['fieldarray'] which are simple fieldnames
    // ==> We first translate $value to the simple fieldname (let's call it the masterFieldName) from
    //     the $_SESSION['survey_X']['fieldnamesInfo'] translation table
    if (isset($_SESSION['survey_' . $surveyid]['fieldnamesInfo'][$value])) {
        $masterFieldName = $_SESSION['survey_' . $surveyid]['fieldnamesInfo'][$value];
    } else {
        // for token refurl, ipaddr...
        $masterFieldName = 'token';
    }
    $value_qid = 0;
    $value_type = '';
    $value_isconditionnal = 'N';
    //$value is the fieldname for the field we are checking for conditions
    foreach ($_SESSION['survey_' . $surveyid]['fieldarray'] as $sfa) {
        // record the qid and question type for future use
        if ($sfa[1] == $masterFieldName) {
            $value_qid = $sfa[0];
            $value_type = $sfa[4];
            $value_isconditionnal = $sfa[7];
            break;
        }
    }
    // check if this question is conditionnal ($sfa[7]): if yes eval conditions
    if ($value_isconditionnal == "Y" && isset($_SESSION['survey_' . $surveyid][$value])) {
        $scenarioquery = "SELECT DISTINCT scenario FROM {{conditions}}" . " WHERE {{conditions}}.qid={$sfa['0']} ORDER BY scenario";
        $scenarioresult = dbExecuteAssoc($scenarioquery);
        $matchfound = 0;
        //$scenario=1;
        //while ($scenario > 0)
        $evalNextScenario = true;
        foreach ($scenarioresult->readAll() as $scenariorow) {
            if ($evalNextScenario !== true) {
                break;
            }
            $aAllCondrows = array();
            $cqval = array();
            $container = array();
            $scenario = $scenariorow['scenario'];
            $currentcfield = "";
            $sConditionsQuery1 = "SELECT {{conditions}}.*, {{questions}}.type " . "FROM {{conditions}}, {{questions}} " . "WHERE {{conditions}}.cqid={{questions}}.qid " . "AND {{conditions}}.qid={$value_qid} " . "AND {{conditions}}.scenario={$scenario} " . "AND {{conditions}}.cfieldname NOT LIKE '{%' " . "ORDER BY {{conditions}}.qid,{{conditions}}.cfieldname";
            $oResult1 = dbExecuteAssoc($sConditionsQuery1) or safeDie($query . "<br />");
            //Checked
            $aConditionsResult1 = $oResult2->readAll();
            //Checked
            $conditionsfound = count($aConditionsResult1);
            $sConditionsQuery2 = "SELECT {{conditions}}.*, '' as type " . "FROM {{conditions}} " . "WHERE " . " {{conditions}}.qid={$value_qid} " . "AND {{conditions}}.scenario={$scenario} " . "AND {{conditions}}.cfieldname LIKE '{%' " . "ORDER BY {{conditions}}.qid,{{conditions}}.cfieldname";
            $oResult2 = dbExecuteAssoc($sConditionsQuery2) or safeDie($querytoken . "<br />");
            $aConditionsResult2 = $oResult2->readAll();
            //Checked
            $conditionsfoundtoken = count($aConditionsResult2);
            $conditionsfound = $conditionsfound + $conditionsfoundtoken;
            foreach ($aConditionsResult2 as $Condrow) {
                $aAllCondrows[] = $Condrow;
            }
            foreach ($aConditionsResult1 as $Condrow) {
                $aAllCondrows[] = $Condrow;
            }
            foreach ($aAllCondrows as $rows) {
                if (preg_match("/^\\+(.*)\$/", $rows['cfieldname'], $cfieldnamematch)) {
                    // this condition uses a single checkbox as source
                    $rows['type'] = "+" . $rows['type'];
                    $rows['cfieldname'] = $cfieldnamematch[1];
                }
                if ($rows['type'] == "M" || $rows['type'] == "P") {
                    $matchfield = $rows['cfieldname'] . $rows['value'];
                    $matchmethod = $rows['method'];
                    $matchvalue = "Y";
                } else {
                    $matchfield = $rows['cfieldname'];
                    $matchmethod = $rows['method'];
                    $matchvalue = $rows['value'];
                }
                $cqval[] = array("cfieldname" => $rows['cfieldname'], "value" => $rows['value'], "type" => $rows['type'], "matchfield" => $matchfield, "matchvalue" => $matchvalue, "matchmethod" => $matchmethod);
                if ($rows['cfieldname'] != $currentcfield) {
                    $container[] = $rows['cfieldname'];
                }
                $currentcfield = $rows['cfieldname'];
            }
            if ($conditionsfound > 0) {
                //At least one match must be found for each "$container"
                $total = 0;
                foreach ($container as $con) {
                    $conditionCanBeEvaluated = true;
                    $addon = 0;
                    foreach ($cqval as $cqv) {
                        //Go through each condition
                        // Replace @SGQA@ condition values
                        // By corresponding value
                        if (preg_match('/^@([0-9]+X[0-9]+X[^@]+)@/', $cqv["matchvalue"], $targetconditionfieldname)) {
                            if (isset($_SESSION['survey_' . $surveyid][$targetconditionfieldname[1]])) {
                                $cqv["matchvalue"] = $_SESSION['survey_' . $surveyid][$targetconditionfieldname[1]];
                            } else {
                                $conditionCanBeEvaluated = false;
                            }
                        }
                        // Replace {TOKEN:XXX} condition values
                        // By corresponding value
                        if ($local_thissurvey['anonymized'] == 'N' && preg_match('/^{TOKEN:([^}]*)}$/', $cqv["matchvalue"], $targetconditiontokenattr)) {
                            if (isset($_SESSION['survey_' . $surveyid]['token']) && in_array(strtolower($targetconditiontokenattr[1]), getTokenConditionsFieldNames($surveyid))) {
                                $cqv["matchvalue"] = getAttributeValue($surveyid, strtolower($targetconditiontokenattr[1]), $_SESSION['survey_' . $surveyid]['token']);
                            } else {
                                $conditionCanBeEvaluated = false;
                            }
                        }
                        // Use == as default operator
                        if (trim($cqv['matchmethod']) == '') {
                            $cqv['matchmethod'] = '==';
                        }
                        if ($cqv['cfieldname'] == $con && $conditionCanBeEvaluated === true) {
                            if (!preg_match("/^{/", $cqv['cfieldname'])) {
                                if (isset($_SESSION['survey_' . $surveyid][$cqv['matchfield']])) {
                                    $comparisonLeftOperand = $_SESSION['survey_' . $surveyid][$cqv['matchfield']];
                                } else {
                                    $comparisonLeftOperand = null;
                                }
                            } elseif ($local_thissurvey['anonymized'] == "N" && preg_match('/^{TOKEN:([^}]*)}$/', $cqv['cfieldname'], $sourceconditiontokenattr)) {
                                if (isset($_SESSION['survey_' . $surveyid]['token']) && in_array(strtolower($sourceconditiontokenattr[1]), getTokenConditionsFieldNames($surveyid))) {
                                    $comparisonLeftOperand = getAttributeValue($surveyid, strtolower($sourceconditiontokenattr[1]), $_SESSION['survey_' . $surveyid]['token']);
                                } else {
                                    $comparisonLeftOperand = null;
                                }
                            } else {
                                $comparisonLeftOperand = null;
                            }
                            if ($cqv['matchmethod'] != "RX") {
                                if (preg_match("/^a(.*)b\$/", $cqv['matchmethod'], $matchmethods)) {
                                    // strings comparizon operator in PHP are the same as numerical operators
                                    $matchOperator = $matchmethods[1];
                                } else {
                                    $matchOperator = $cqv['matchmethod'];
                                }
                                if (isset($comparisonLeftOperand) && !is_null($comparisonLeftOperand) && eval('if (trim($comparisonLeftOperand) ' . $matchOperator . ' trim($cqv["matchvalue"]) ) {return true;} else {return false;}')) {
                                    //plug successful matches into appropriate container
                                    $addon = 1;
                                }
                            } elseif (isset($comparisonLeftOperand) && !is_null($comparisonLeftOperand) && preg_match('/' . $cqv["matchvalue"] . '/', $comparisonLeftOperand)) {
                                $addon = 1;
                            }
                        }
                    }
                    if ($addon == 1) {
                        $total++;
                    }
                }
                if ($total == count($container)) {
                    $matchfound = 1;
                    $evalNextScenario = false;
                    // Don't look for other scenario's.
                }
                unset($cqval);
                unset($container);
            } else {
                //Curious there is no condition for this question in this scenario
                // this is not a normal behaviour, but I propose to defaults to a
                // condition-matched state in this case
                $matchfound = 1;
                $evalNextScenario = false;
            }
        }
        // while ($scenario)
        if ($matchfound == 0) {
            //If this is not a "moveprev" then
            // Reset the value in SESSION
            //if(isset($move) && $move != "moveprev")
            //{
            $_SESSION['survey_' . $surveyid][$value] = "";
            $fieldisdisplayed = false;
            //}
        }
    }
    if ($value_qid != 0) {
        // not token masterFieldname
        $value_qa = getQuestionAttributeValues($value_qid, $value_type);
    }
    if ($fieldisdisplayed === true && isset($value_qa) && (isset($value_qa['array_filter']) && trim($value_qa['array_filter']) != '' || isset($value_qa['array_filter_exclude']) && trim($value_qa['array_filter_exclude']) != '')) {
        // check if array_filter//array_filter_exclude have hidden the field
        $value_code = preg_replace("/{$masterFieldName}(.*)/", "\$1", $value);
        //If this question is a multi-flexible, the value_code will be both the array_filter value
        // (at the beginning) and then a labelset value after an underscore
        // ie: 2_1 for answer code=2 and labelset code=1 then 2_2 for answer_code=2 and
        // labelset code=2. So for these question types we need to split it again at the underscore!
        // 1. Find out if this is question type ":" or ";"
        if ($value_type == ";" || $value_type == ":") {
            list($value_code, $value_label) = explode("_", $value_code);
        }
        if (isset($value_qa['array_filter_exclude'])) {
            $arrayfilterXcludes_selected_codes = getArrayFilterExcludesForQuestion($value_qid);
            if ($arrayfilterXcludes_selected_codes !== false && in_array($value_code, $arrayfilterXcludes_selected_codes)) {
                $fieldisdisplayed = false;
            }
        } elseif (isset($value_qa['array_filter'])) {
            $arrayfilter_selected_codes = getArrayFiltersForQuestion($value_qid);
            if ($arrayfilter_selected_codes !== false && !in_array($value_code, $arrayfilter_selected_codes)) {
                $fieldisdisplayed = false;
            }
        }
    }
    return $fieldisdisplayed;
}
Ejemplo n.º 4
0
/**
 * Parses the style tags of the given xml element and uses them to generate
 * the associated html code.
 * @param SimpleXMLElement $xmlElement
 * @param boolean $shouldAddSwapToLinks
 * @param string $cssMenuClassName
 *
 * @return string
 * @author Andrew Darwin <*****@*****.**>
 */
function getElementContentWithStyleTags($xmlElement, $shouldAddSwapToLinks, $cssMenuClassName)
{
    $header = "getElementContentWithStyleTags(): ";
    logMessage("{$header} Beginning call...\n" . "xmlElement = '" . getTrimmed($xmlElement) . "'\n" . "shouldAddSwapToLinks = some boolean\n" . "cssMenuClassName = '{$cssMenuClassName}'");
    $attributes = $xmlElement->attributes();
    logMessage("{$header} Obtained attributes from XML Element, '{$xmlElement}'");
    $output = "";
    $prefix = "";
    $suffix = "";
    $urlSpecified = false;
    $urlOpenTag = "";
    $urlCloseTag = "";
    $outputHTMLAttributes = "";
    if ($attributes != null) {
        foreach ($attributes as $attribute) {
            $currentAttributeName = $attribute->getName();
            switch ($currentAttributeName) {
                case "style":
                    $styles = formatStyleAttribute($attribute);
                    foreach ($styles as $style) {
                        addToPrefix($prefix, "<{$style}>");
                        addToSuffix($suffix, "</{$style}>");
                    }
                    break;
                case "css":
                    $outputHTMLAttributes = "class=\"{$attribute}\"";
                    break;
                case "url":
                    // Must apply url last, so lets save it to a variable and do
                    // stuff with it later
                    $urlSpecified = true;
                    $loadURLPrefix = "";
                    if (strpos(getcwd(), "resources/scripts") == false) {
                        $loadURLPrefix = "resources/scripts/";
                    }
                    // Escape any necessary characters from the url
                    $attribute = clean_url($attribute);
                    logMessage("{$header} Clean url = '{$attribute}'");
                    $target = getAttributeValue($xmlElement, "target");
                    $isExternal = is_link_external($attribute);
                    $loadURLPrefix .= "loadURL.php";
                    $extension = pathinfo($attribute, PATHINFO_EXTENSION);
                    if ($extension == "xml") {
                        $href = "'{$loadURLPrefix}?url={$attribute}'";
                    } else {
                        $href = "'{$attribute}'";
                    }
                    if ($target == "new_tab" || $target != "same_tab" && is_link_external($attribute)) {
                        $href .= " target='_blank'";
                        $shouldAddSwapToLinks = false;
                    }
                    $urlOpenTag = "<a href={$href}";
                    if ($shouldAddSwapToLinks) {
                        $urlOpenTag .= " target='innerframe'";
                    }
                    if ($cssMenuClassName != "") {
                        $urlOpenTag .= " class='{$cssMenuClassName}'";
                    }
                    $urlOpenTag .= ">";
                    $urlCloseTag = "</a>";
            }
        }
        if ($urlSpecified) {
            addToPrefix($prefix, $urlOpenTag);
            addToSuffix($suffix, $urlCloseTag);
        }
    } else {
        logMessage("{$header} The XML Element, '{$xmlElement}' had no attributes. " . "Continue without applying any attributes or styles.");
    }
    $innerContent = getTrimmed($xmlElement);
    if (hasChildren($xmlElement)) {
        $children = $xmlElement->children();
        $child = $children[0];
        if ($child->getName() == "link") {
            logMessage("{$header} Determined that XML Element, '" . getTrimmed($xmlElement) . "' has link children. Set " . "inner content to [recursive call]...");
            $innerContent = parseLink($xmlElement);
            logMessage("{$header} InnerContent is now '{$innerContent}' after " . "calling parseLink");
        } else {
            logMessage("{$header} Determined xml element, '" . getTrimmed($xmlElement) . "' has children, but not LINK children");
        }
    } else {
        logMessage("{$header} Determined that XML Element, '" . getTrimmed($xmlElement) . "' does not have any link " . "children. Set inner content to '" . getTrimmed($xmlElement) . "'");
    }
    $output = $prefix . $innerContent . $suffix;
    logMessage("{$header} Return '{$output}'");
    return $output;
}