当前位置: 首页>>代码示例>>PHP>>正文


PHP convertCSVRowToArray函数代码示例

本文整理汇总了PHP中convertCSVRowToArray函数的典型用法代码示例。如果您正苦于以下问题:PHP convertCSVRowToArray函数的具体用法?PHP convertCSVRowToArray怎么用?PHP convertCSVRowToArray使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了convertCSVRowToArray函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CSVImportSurvey


//.........这里部分代码省略.........
    } else {
        $importresults['quotamembers'] = 0;
    }
    if (isset($quotalsarray)) {
        $importresults['quotals'] = count($quotalsarray);
    } else {
        $importresults['quotals'] = 0;
    }
    // CREATE SURVEY
    if ($importresults['surveys'] > 0) {
        $importresults['surveys']--;
    }
    if ($importresults['answers'] > 0) {
        $importresults['answers'] = ($importresults['answers'] - 1) / $importresults['languages'];
    }
    if ($importresults['groups'] > 0) {
        $countgroups = ($importresults['groups'] - 1) / $importresults['languages'];
    }
    if ($importresults['questions'] > 0) {
        $importresults['questions'] = ($importresults['questions'] - 1) / $importresults['languages'];
    }
    if ($importresults['assessments'] > 0) {
        $importresults['assessments']--;
    }
    if ($importresults['conditions'] > 0) {
        $importresults['conditions']--;
    }
    if ($importresults['labelsets'] > 0) {
        $importresults['labelsets']--;
    }
    if ($importresults['quota'] > 0) {
        $importresults['quota']--;
    }
    $sfieldorders = convertCSVRowToArray($surveyarray[0], ',', '"');
    $sfieldcontents = convertCSVRowToArray($surveyarray[1], ',', '"');
    $surveyrowdata = array_combine($sfieldorders, $sfieldcontents);
    $iOldSID = $surveyrowdata["sid"];
    if (!$iOldSID) {
        if ($importingfrom == "http") {
            $importsurvey .= "<br /><div class='warningheader'>" . $clang->gT("Error") . "</div><br />\n";
            $importsurvey .= $clang->gT("Import of this survey file failed") . "<br />\n";
            $importsurvey .= $clang->gT("File does not contain LimeSurvey data in the correct format.") . "<br /><br />\n";
            //Couldn't find the SID - cannot continue
            $importsurvey .= "<input type='submit' value='" . $clang->gT("Main Admin Screen") . "' onclick=\"window.open('{$scriptname}', '_top')\" />\n";
            $importsurvey .= "</div>\n";
            unlink($sFullFilepath);
            //Delete the uploaded file
            return;
        } else {
            $clang->eT("Import of this survey file failed") . "\n" . $clang->gT("File does not contain LimeSurvey data in the correct format.") . "\n";
            return;
        }
    }
    if ($iDesiredSurveyId != NULL) {
        $iNewSID = GetNewSurveyID($iDesiredSurveyId);
    } else {
        $iNewSID = GetNewSurveyID($iOldSID);
    }
    $insert = $surveyarray[0];
    $sfieldorders = convertCSVRowToArray($surveyarray[0], ',', '"');
    $sfieldcontents = convertCSVRowToArray($surveyarray[1], ',', '"');
    $surveyrowdata = array_combine($sfieldorders, $sfieldcontents);
    // Set new owner ID
    $surveyrowdata['owner_id'] = Yii::app()->session['loginID'];
    // Set new survey ID
    $surveyrowdata['sid'] = $iNewSID;
开发者ID:rawaludin,项目名称:LimeSurvey,代码行数:67,代码来源:import_helper.php

示例2: convertCSVRowToArray

                    {
                        $ignoredcolumns[]=$fieldname;
                    }
                }
                if (!in_array('firstname',$firstline) || !in_array('lastname',$firstline) || !in_array('email',$firstline))
                {
                    $tokenoutput .= "<div class='warningheader'>".$clang->gT("Error: Your uploaded file is missing one or more of the mandatory columns: 'firstname', 'lastname' or 'email'")."</div><br />";
                    $recordcount=count($tokenlistarray);
                    break;
                }

            }
            else
            {

                $line = convertCSVRowToArray($buffer,$separator,'"');

                if (count($firstline)!=count($line))
                {
                    $invalidformatlist[]=$recordcount;
                    $recordcount++;
                    continue;
                }
                $writearray=array_combine($firstline,$line);

                //kick out ignored columns
                foreach ($ignoredcolumns  as $column)
                {
                    unset($writearray[$column]);
                }
                $dupfound=false;
开发者ID:nmklong,项目名称:limesurvey-cdio3,代码行数:31,代码来源:tokens.php

示例3: doesImportArraySupportLanguage

/**
*  Checks that each object from an array of CSV data [question-rows,answer-rows,labelsets-row] supports at least a given language
*
* @param mixed $csvarray array with a line of csv data per row
* @param mixed $idkeysarray  array of integers giving the csv-row numbers of the object keys
* @param mixed $langfieldnum  integer giving the csv-row number of the language(s) filed
*        ==> the language field  can be a single language code or a
*            space separated language code list
* @param mixed $langcode  the language code to be tested
* @param mixed $hasheader  if we should strip off the first line (if it contains headers)
*/
function doesImportArraySupportLanguage($csvarray, $idkeysarray, $langfieldnum, $langcode, $hasheader = false)
{
    // An array with one row per object id and langsupport status as value
    $objlangsupportarray = array();
    if ($hasheader === true) {
        // stripping first row to skip headers if any
        array_shift($csvarray);
    }
    foreach ($csvarray as $csvrow) {
        $rowcontents = convertCSVRowToArray($csvrow, ',', '"');
        $rowid = "";
        foreach ($idkeysarray as $idfieldnum) {
            $rowid .= $rowcontents[$idfieldnum] . "-";
        }
        $rowlangarray = explode(" ", @$rowcontents[$langfieldnum]);
        if (!isset($objlangsupportarray[$rowid])) {
            if (array_search($langcode, $rowlangarray) !== false) {
                $objlangsupportarray[$rowid] = "true";
            } else {
                $objlangsupportarray[$rowid] = "false";
            }
        } else {
            if ($objlangsupportarray[$rowid] == "false" && array_search($langcode, $rowlangarray) !== false) {
                $objlangsupportarray[$rowid] = "true";
            }
        }
    }
    // end foreach rown
    // If any of the object doesn't support the given language, return false
    if (array_search("false", $objlangsupportarray) === false) {
        return true;
    } else {
        return false;
    }
}
开发者ID:GuillaumeSmaha,项目名称:LimeSurvey,代码行数:46,代码来源:common_helper.php

示例4: CSVImportLabelset

function CSVImportLabelset($sFullFilepath, $options)
{
    global $dbprefix, $connect, $clang;
    $results['labelsets'] = 0;
    $results['labels'] = 0;
    $results['warnings'] = array();
    $csarray = buildLabelSetCheckSumArray();
    //$csarray is now a keyed array with the Checksum of each of the label sets, and the lid as the key
    $handle = fopen($sFullFilepath, "r");
    while (!feof($handle)) {
        $buffer = fgets($handle);
        //To allow for very long survey welcomes (up to 10k)
        $bigarray[] = $buffer;
    }
    fclose($handle);
    if (substr($bigarray[0], 0, 27) != "# LimeSurvey Label Set Dump" && substr($bigarray[0], 0, 28) != "# PHPSurveyor Label Set Dump") {
        $results['fatalerror'] = $clang->gT("This file is not a LimeSurvey label set file. Import failed.");
        return $results;
    }
    for ($i = 0; $i < 9; $i++) {
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    //LABEL SETS
    if (array_search("# LABELS TABLE\n", $bigarray)) {
        $stoppoint = array_search("# LABELS TABLE\n", $bigarray);
    } elseif (array_search("# LABELS TABLE\r\n", $bigarray)) {
        $stoppoint = array_search("# LABELS TABLE\r\n", $bigarray);
    } else {
        $stoppoint = count($bigarray) - 1;
    }
    for ($i = 0; $i <= $stoppoint + 1; $i++) {
        if ($i < $stoppoint - 2) {
            $labelsetsarray[] = $bigarray[$i];
        }
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    //LABELS
    $stoppoint = count($bigarray) - 1;
    for ($i = 0; $i < $stoppoint; $i++) {
        // do not import empty lines
        if (trim($bigarray[$i]) != '') {
            $labelsarray[] = $bigarray[$i];
        }
        unset($bigarray[$i]);
    }
    $countlabelsets = count($labelsetsarray) - 1;
    $countlabels = count($labelsarray) - 1;
    if (isset($labelsetsarray) && $labelsetsarray) {
        $count = 0;
        foreach ($labelsetsarray as $lsa) {
            $fieldorders = convertCSVRowToArray($labelsetsarray[0], ',', '"');
            $fieldcontents = convertCSVRowToArray($lsa, ',', '"');
            if ($count == 0) {
                $count++;
                continue;
            }
            $labelsetrowdata = array_combine($fieldorders, $fieldcontents);
            // Save old labelid
            $oldlid = $labelsetrowdata['lid'];
            // set the new language
            unset($labelsetrowdata['lid']);
            $newvalues = array_values($labelsetrowdata);
            $newvalues = array_map(array(&$connect, "qstr"), $newvalues);
            // quote everything accordingly
            $lsainsert = "insert INTO {$dbprefix}labelsets (" . implode(',', array_keys($labelsetrowdata)) . ") VALUES (" . implode(',', $newvalues) . ")";
            //handle db prefix
            $lsiresult = $connect->Execute($lsainsert);
            $results['labelsets']++;
            // Get the new insert id for the labels inside this labelset
            $newlid = $connect->Insert_ID("{$dbprefix}labelsets", 'lid');
            if ($labelsarray) {
                $count = 0;
                $lfieldorders = convertCSVRowToArray($labelsarray[0], ',', '"');
                unset($labelsarray[0]);
                foreach ($labelsarray as $la) {
                    $lfieldcontents = convertCSVRowToArray($la, ',', '"');
                    // Combine into one array with keys and values since its easier to handle
                    $labelrowdata = array_combine($lfieldorders, $lfieldcontents);
                    $labellid = $labelrowdata['lid'];
                    if ($labellid == $oldlid) {
                        $labelrowdata['lid'] = $newlid;
                        // translate internal links
                        $labelrowdata['title'] = translink('label', $oldlid, $newlid, $labelrowdata['title']);
                        if (!isset($labelrowdata["assessment_value"])) {
                            $labelrowdata["assessment_value"] = (int) $labelrowdata["code"];
                        }
                        $newvalues = array_values($labelrowdata);
                        $newvalues = array_map(array(&$connect, "qstr"), $newvalues);
                        // quote everything accordingly
                        $lainsert = "insert INTO {$dbprefix}labels (" . implode(',', array_keys($labelrowdata)) . ") VALUES (" . implode(',', $newvalues) . ")";
                        //handle db prefix
                        $liresult = $connect->Execute($lainsert);
                        $results['labels']++;
                    }
                }
            }
            //CHECK FOR DUPLICATE LABELSETS
            if (isset($_POST['checkforduplicates'])) {
//.........这里部分代码省略.........
开发者ID:ddrmoscow,项目名称:queXS,代码行数:101,代码来源:importlabel.php

示例5: uploadCSV

 function uploadCSV()
 {
     $clang = $this->getController()->lang;
     unset(Yii::app()->session['summary']);
     $characterset = Yii::app()->request->getPost('characterset');
     $separator = Yii::app()->request->getPost('separatorused');
     $newarray = Yii::app()->request->getPost('newarray');
     $mappedarray = Yii::app()->request->getPost('mappedarray', false);
     $filterblankemails = Yii::app()->request->getPost('filterbea');
     $overwrite = Yii::app()->request->getPost('overwrite');
     $sFilePath = Yii::app()->getConfig('tempdir') . '/' . basename(Yii::app()->request->getPost('fullfilepath'));
     $errorinupload = "";
     $recordcount = 0;
     $mandatory = 0;
     $mincriteria = 0;
     $imported = 0;
     $dupcount = 0;
     $overwritten = 0;
     $dupreason = "nameemail";
     //Default duplicate comparison method
     $duplicatelist = array();
     $invalidemaillist = array();
     $invalidformatlist = array();
     $invalidattribute = array();
     $invalidparticipantid = array();
     $aGlobalErrors = array();
     /* If no mapped array */
     if (!$mappedarray) {
         $mappedarray = array();
     }
     /* Adjust system settings to read file with MAC line endings */
     @ini_set('auto_detect_line_endings', true);
     /* Open the uploaded file into an array */
     $tokenlistarray = file($sFilePath);
     // open it and trim the endings
     $separator = Yii::app()->request->getPost('separatorused');
     $uploadcharset = Yii::app()->request->getPost('characterset');
     /* The $newarray contains a list of fields that will be used
        to create new attributes */
     if (!empty($newarray)) {
         /* Create a new entry in the lime_participant_attribute_names table,
            and it's associated lime_participant_attribute_names_lang table
            for each NEW attribute being created in this import process */
         foreach ($newarray as $key => $value) {
             $aData = array('attribute_type' => 'TB', 'attribute_name' => $value, 'visible' => 'FALSE');
             $insertid = ParticipantAttributeName::model()->storeAttributeCSV($aData);
             /* Keep a record of the attribute_id for this new attribute
                in the $mappedarray string. For example, if the new attribute
                has attribute_id of 35 and is called "gender",
                $mappedarray['35']='gender' */
             $mappedarray[$insertid] = $value;
         }
     }
     if (!isset($uploadcharset)) {
         $uploadcharset = 'auto';
     }
     foreach ($tokenlistarray as $buffer) {
         //Iterate through the CSV file line by line
         $buffer = @mb_convert_encoding($buffer, "UTF-8", $uploadcharset);
         $firstname = "";
         $lastname = "";
         $email = "";
         $language = "";
         if ($recordcount == 0) {
             //The first time we iterate through the file we look at the very
             //first line, which contains field names, not values to import
             // Pick apart the first line
             $buffer = removeBOM($buffer);
             $attrid = ParticipantAttributeName::model()->getAttributeID();
             $allowedfieldnames = array('participant_id', 'firstname', 'lastname', 'email', 'language', 'blacklisted');
             $aFilterDuplicateFields = array('firstname', 'lastname', 'email');
             if (!empty($mappedarray)) {
                 foreach ($mappedarray as $key => $value) {
                     array_push($allowedfieldnames, strtolower($value));
                 }
             }
             //For Attributes
             switch ($separator) {
                 case 'comma':
                     $separator = ',';
                     break;
                 case 'semicolon':
                     $separator = ';';
                     break;
                 default:
                     $comma = substr_count($buffer, ',');
                     $semicolon = substr_count($buffer, ';');
                     if ($semicolon > $comma) {
                         $separator = ';';
                     } else {
                         $separator = ',';
                     }
             }
             $firstline = convertCSVRowToArray($buffer, $separator, '"');
             $firstline = array_map('trim', $firstline);
             $ignoredcolumns = array();
             //now check the first line for invalid fields
             foreach ($firstline as $index => $fieldname) {
                 $firstline[$index] = preg_replace("/(.*) <[^,]*>\$/", "\$1", $fieldname);
                 $fieldname = $firstline[$index];
//.........这里部分代码省略.........
开发者ID:jdbaltazar,项目名称:survey-office,代码行数:101,代码来源:participantsaction.php

示例6: CSVImportSurvey


//.........这里部分代码省略.........

    //Whatever is the last table - currently
    //QUOTA LANGUAGE SETTINGS
    $stoppoint = count($bigarray)-1;
    for ($i=0; $i<$stoppoint-1; $i++)
    {
        if ($i<=$stoppoint) {$quotalsarray[] = $bigarray[$i];}
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);

    if (isset($surveyarray)) {$importresults['surveys'] = count($surveyarray);} else {$importresults['surveys'] = 0;}
    if (isset($surveylsarray)) {$importresults['languages'] = count($surveylsarray)-1;} else {$importresults['languages'] = 1;}
    if (isset($grouparray)) {$importresults['groups'] = count($grouparray)-1;} else {$importresults['groups'] = 0;}
    if (isset($questionarray)) {$importresults['questions'] = count($questionarray);} else {$importresults['questions']=0;}
    if (isset($answerarray)) {$importresults['answers'] = count($answerarray);} else {$importresults['answers']=0;}
    if (isset($conditionsarray)) {$importresults['conditions'] = count($conditionsarray);} else {$importresults['conditions']=0;}
    if (isset($labelsetsarray)) {$importresults['labelsets'] = count($labelsetsarray);} else {$importresults['labelsets']=0;}
    if (isset($assessmentsarray)) {$importresults['assessments']=count($assessmentsarray);} else {$importresults['assessments']=0;}
    if (isset($quotaarray)) {$importresults['quota']=count($quotaarray);} else {$importresults['quota']=0;}
    if (isset($quotamembersarray)) {$importresults['quotamembers']=count($quotamembersarray);} else {$importresults['quotamembers']=0;}
    if (isset($quotalsarray)) {$importresults['quotals']=count($quotalsarray);} else {$importresults['quotals']=0;}

    // CREATE SURVEY

    if ($importresults['surveys']>0){$importresults['surveys']--;};
    if ($importresults['answers']>0){$importresults['answers']=($importresults['answers']-1)/$importresults['languages'];};
    if ($importresults['groups']>0){$countgroups=($importresults['groups']-1)/$importresults['languages'];};
    if ($importresults['questions']>0){$importresults['questions']=($importresults['questions']-1)/$importresults['languages'];};
    if ($importresults['assessments']>0){$importresults['assessments']--;};
    if ($importresults['conditions']>0){$importresults['conditions']--;};
    if ($importresults['labelsets']>0){$importresults['labelsets']--;};
    if ($importresults['quota']>0){$importresults['quota']--;};
    $sfieldorders  =convertCSVRowToArray($surveyarray[0],',','"');
    $sfieldcontents=convertCSVRowToArray($surveyarray[1],',','"');
    $surveyrowdata=array_combine($sfieldorders,$sfieldcontents);
    $oldsid=$surveyrowdata["sid"];

    if($iDesiredSurveyId!=NULL)
        $oldsid = $iDesiredSurveyId;

    if (!$oldsid)
    {
        if ($importingfrom == "http")
        {
            $importsurvey .= "<br /><div class='warningheader'>".$clang->gT("Error")."</div><br />\n";
            $importsurvey .= $clang->gT("Import of this survey file failed")."<br />\n";
            $importsurvey .= $clang->gT("File does not contain LimeSurvey data in the correct format.")."<br /><br />\n"; //Couldn't find the SID - cannot continue
            $importsurvey .= "<input type='submit' value='".$clang->gT("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\" />\n";
            $importsurvey .= "</div>\n";
            unlink($sFullFilepath); //Delete the uploaded file
            return;
        }
        else
        {
            echo $clang->gT("Import of this survey file failed")."\n".$clang->gT("File does not contain LimeSurvey data in the correct format.")."\n";
            return;
        }
    }

    $newsid = GetNewSurveyID($oldsid);

    $insert=$surveyarray[0];
    $sfieldorders  =convertCSVRowToArray($surveyarray[0],',','"');
    $sfieldcontents=convertCSVRowToArray($surveyarray[1],',','"');
    $surveyrowdata=array_combine($sfieldorders,$sfieldcontents);
开发者ID:nmklong,项目名称:limesurvey-cdio3,代码行数:67,代码来源:import_functions.php

示例7: importQuestion


//.........这里部分代码省略.........
     //LABELS
     if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray)) {
         $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
     } elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray)) {
         $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
     } else {
         $stoppoint = count($bigarray) - 1;
     }
     for ($i = 0; $i <= $stoppoint + 1; $i++) {
         if ($i < $stoppoint - 2) {
             $labelsarray[] = $bigarray[$i];
         }
         unset($bigarray[$i]);
     }
     $bigarray = array_values($bigarray);
     $this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
     //Question_attributes
     if (!isset($noconditions) || $noconditions != "Y") {
         $stoppoint = count($bigarray);
         for ($i = 0; $i <= $stoppoint + 1; $i++) {
             if ($i < $stoppoint - 1) {
                 $question_attributesarray[] = $bigarray[$i];
             }
             unset($bigarray[$i]);
         }
     }
     $bigarray = array_values($bigarray);
     if (isset($questionarray)) {
         $countquestions = count($questionarray) - 1;
     } else {
         $countquestions = 0;
     }
     if (isset($answerarray)) {
         $answerfieldnames = convertCSVRowToArray($answerarray[0], ',', '"');
         unset($answerarray[0]);
         $countanswers = count($answerarray);
     } else {
         $countanswers = 0;
     }
     if (isset($labelsetsarray)) {
         $countlabelsets = count($labelsetsarray) - 1;
     } else {
         $countlabelsets = 0;
     }
     if (isset($labelsarray)) {
         $countlabels = count($labelsarray) - 1;
     } else {
         $countlabels = 0;
     }
     if (isset($question_attributesarray)) {
         $countquestion_attributes = count($question_attributesarray) - 1;
     } else {
         $countquestion_attributes = 0;
     }
     $languagesSupported = array();
     // this array will keep all the languages supported for the survey
     // Let's check that imported objects support at least the survey's baselang
     $langcode = GetBaseLanguageFromSurveyID($surveyid);
     $languagesSupported[$langcode] = 1;
     // adds the base language to the list of supported languages
     $this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
     if ($countquestions > 0) {
         $questionfieldnames = convertCSVRowToArray($questionarray[0], ',', '"');
         $langfieldnum = array_search("language", $questionfieldnames);
         $qidfieldnum = array_search("qid", $questionfieldnames);
         $questionssupportbaselang = bDoesImportarraySupportsLanguage($questionarray, array($qidfieldnum), $langfieldnum, $langcode, true);
开发者ID:rkaldung,项目名称:LimeSurvey,代码行数:67,代码来源:lsrc.helper.php

示例8: CSVImportGroup


//.........这里部分代码省略.........
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    //LABELS
    if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray)) {
        $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
    } elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray)) {
        $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
    } else {
        $stoppoint = count($bigarray) - 1;
    }
    for ($i = 0; $i <= $stoppoint + 1; $i++) {
        if ($i < $stoppoint - 2) {
            $labelsarray[] = $bigarray[$i];
        }
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    //Question attributes
    if (!isset($noconditions) || $noconditions != "Y") {
        // stoppoint is the last line number
        // this is an empty line after the QA CSV lines
        $stoppoint = count($bigarray) - 1;
        for ($i = 0; $i <= $stoppoint + 1; $i++) {
            if ($i <= $stoppoint - 1) {
                $question_attributesarray[] = $bigarray[$i];
            }
            unset($bigarray[$i]);
        }
    }
    $bigarray = array_values($bigarray);
    $countgroups = 0;
    if (isset($questionarray)) {
        $questionfieldnames = convertCSVRowToArray($questionarray[0], ',', '"');
        unset($questionarray[0]);
        $countquestions = 0;
    }
    if (isset($answerarray)) {
        $answerfieldnames = convertCSVRowToArray($answerarray[0], ',', '"');
        unset($answerarray[0]);
        $countanswers = count($answerarray);
    } else {
        $countanswers = 0;
    }
    $aLanguagesSupported = array();
    // this array will keep all the languages supported for the survey
    $sBaseLanguage = GetBaseLanguageFromSurveyID($newsid);
    $aLanguagesSupported[] = $sBaseLanguage;
    // adds the base language to the list of supported languages
    $aLanguagesSupported = array_merge($aLanguagesSupported, GetAdditionalLanguagesFromSurveyID($newsid));
    // Let's check that imported objects support at least the survey's baselang
    $langcode = GetBaseLanguageFromSurveyID($newsid);
    if (isset($grouparray)) {
        $groupfieldnames = convertCSVRowToArray($grouparray[0], ',', '"');
        $langfieldnum = array_search("language", $groupfieldnames);
        $gidfieldnum = array_search("gid", $groupfieldnames);
        $groupssupportbaselang = bDoesImportarraySupportsLanguage($grouparray, array($gidfieldnum), $langfieldnum, $sBaseLanguage, true);
        if (!$groupssupportbaselang) {
            $results['fatalerror'] = $clang->gT("You can't import a group which doesn't support at least the survey base language.");
            return $results;
        }
    }
    if (isset($questionarray)) {
        $langfieldnum = array_search("language", $questionfieldnames);
        $qidfieldnum = array_search("qid", $questionfieldnames);
        $questionssupportbaselang = bDoesImportarraySupportsLanguage($questionarray, array($qidfieldnum), $langfieldnum, $sBaseLanguage, true);
开发者ID:ddrmoscow,项目名称:queXS,代码行数:67,代码来源:importgroup.php

示例9: import

 /**
  * import from csv
  */
 function import($iSurveyId)
 {
     $clang = $this->getController()->lang;
     $iSurveyId = (int) $iSurveyId;
     if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'import')) {
         Yii::app()->session['flashmessage'] = $clang->gT("You do not have sufficient rights to access this page.");
         $this->getController()->redirect(array("/admin/survey/sa/view/surveyid/{$iSurveyId}"));
     }
     // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
     $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
     if (!$bTokenExists) {
         self::_newtokentable($iSurveyId);
     }
     App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . 'tokens.js');
     $aEncodings = aEncodingsArray();
     if (Yii::app()->request->getPost('submit')) {
         if (Yii::app()->request->getPost('csvcharset') && Yii::app()->request->getPost('csvcharset')) {
             $uploadcharset = Yii::app()->request->getPost('csvcharset');
             if (!array_key_exists($uploadcharset, $aEncodings)) {
                 $uploadcharset = 'auto';
             }
             $filterduplicatetoken = Yii::app()->request->getPost('filterduplicatetoken') && Yii::app()->request->getPost('filterduplicatetoken') == 'on';
             $filterblankemail = Yii::app()->request->getPost('filterblankemail') && Yii::app()->request->getPost('filterblankemail') == 'on';
         }
         $attrfieldnames = getAttributeFieldNames($iSurveyId);
         $duplicatelist = array();
         $invalidemaillist = array();
         $invalidformatlist = array();
         $firstline = array();
         $sPath = Yii::app()->getConfig('tempdir');
         $sFileTmpName = $_FILES['the_file']['tmp_name'];
         $sFilePath = $sPath . '/' . randomChars(20);
         if (!@move_uploaded_file($sFileTmpName, $sFilePath)) {
             $aData['sError'] = $clang->gT("Upload file not found. Check your permissions and path ({$sFilePath}) for the upload directory");
             $aData['aEncodings'] = $aEncodings;
             $aData['iSurveyId'] = $aData['surveyid'] = $iSurveyId;
             $aData['thissurvey'] = getSurveyInfo($iSurveyId);
             $this->_renderWrappedTemplate('token', array('tokenbar', 'csvupload'), $aData);
         } else {
             $xz = 0;
             $recordcount = 0;
             $xv = 0;
             // This allows to read file with MAC line endings too
             @ini_set('auto_detect_line_endings', true);
             // open it and trim the ednings
             $tokenlistarray = file($sFilePath);
             $sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language;
             if (!Yii::app()->request->getPost('filterduplicatefields') || Yii::app()->request->getPost('filterduplicatefields') && count(Yii::app()->request->getPost('filterduplicatefields')) == 0) {
                 $filterduplicatefields = array('firstname', 'lastname', 'email');
             } else {
                 $filterduplicatefields = Yii::app()->request->getPost('filterduplicatefields');
             }
             $separator = returnGlobal('separator');
             foreach ($tokenlistarray as $buffer) {
                 $buffer = @mb_convert_encoding($buffer, "UTF-8", $uploadcharset);
                 if ($recordcount == 0) {
                     // Parse first line (header) from CSV
                     $buffer = removeBOM($buffer);
                     $allowedfieldnames = array('firstname', 'lastname', 'email', 'emailstatus', 'token', 'language', 'validfrom', 'validuntil', 'usesleft');
                     $allowedfieldnames = array_merge($attrfieldnames, $allowedfieldnames);
                     switch ($separator) {
                         case 'comma':
                             $separator = ',';
                             break;
                         case 'semicolon':
                             $separator = ';';
                             break;
                         default:
                             $comma = substr_count($buffer, ',');
                             $semicolon = substr_count($buffer, ';');
                             if ($semicolon > $comma) {
                                 $separator = ';';
                             } else {
                                 $separator = ',';
                             }
                     }
                     $firstline = convertCSVRowToArray($buffer, $separator, '"');
                     $firstline = array_map('trim', $firstline);
                     $ignoredcolumns = array();
                     // Now check the first line for invalid fields
                     foreach ($firstline as $index => $fieldname) {
                         $firstline[$index] = preg_replace("/(.*) <[^,]*>\$/", "\$1", $fieldname);
                         $fieldname = $firstline[$index];
                         if (!in_array($fieldname, $allowedfieldnames)) {
                             $ignoredcolumns[] = $fieldname;
                         }
                     }
                     if (!in_array('firstname', $firstline) || !in_array('lastname', $firstline) || !in_array('email', $firstline)) {
                         $recordcount = count($tokenlistarray);
                         break;
                     }
                 } else {
                     $line = convertCSVRowToArray($buffer, $separator, '"');
                     if (count($firstline) != count($line)) {
                         $invalidformatlist[] = $recordcount;
                         $recordcount++;
                         continue;
//.........这里部分代码省略.........
开发者ID:jdbaltazar,项目名称:survey-office,代码行数:101,代码来源:tokens.php

示例10: import

 /**
  * import from csv
  */
 function import($iSurveyId)
 {
     // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
     $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
     if (!$bTokenExists) {
         self::_newtokentable($iSurveyId);
     }
     $clang = $this->getController()->lang;
     $iSurveyId = (int) $iSurveyId;
     if (!hasSurveyPermission($iSurveyId, 'tokens', 'create')) {
         die('access denied');
     }
     $this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . 'tokens.js');
     $aEncodings = array("armscii8" => $clang->gT("ARMSCII-8 Armenian"), "ascii" => $clang->gT("US ASCII"), "auto" => $clang->gT("Automatic"), "big5" => $clang->gT("Big5 Traditional Chinese"), "binary" => $clang->gT("Binary pseudo charset"), "cp1250" => $clang->gT("Windows Central European"), "cp1251" => $clang->gT("Windows Cyrillic"), "cp1256" => $clang->gT("Windows Arabic"), "cp1257" => $clang->gT("Windows Baltic"), "cp850" => $clang->gT("DOS West European"), "cp852" => $clang->gT("DOS Central European"), "cp866" => $clang->gT("DOS Russian"), "cp932" => $clang->gT("SJIS for Windows Japanese"), "dec8" => $clang->gT("DEC West European"), "eucjpms" => $clang->gT("UJIS for Windows Japanese"), "euckr" => $clang->gT("EUC-KR Korean"), "gb2312" => $clang->gT("GB2312 Simplified Chinese"), "gbk" => $clang->gT("GBK Simplified Chinese"), "geostd8" => $clang->gT("GEOSTD8 Georgian"), "greek" => $clang->gT("ISO 8859-7 Greek"), "hebrew" => $clang->gT("ISO 8859-8 Hebrew"), "hp8" => $clang->gT("HP West European"), "keybcs2" => $clang->gT("DOS Kamenicky Czech-Slovak"), "koi8r" => $clang->gT("KOI8-R Relcom Russian"), "koi8u" => $clang->gT("KOI8-U Ukrainian"), "latin1" => $clang->gT("cp1252 West European"), "latin2" => $clang->gT("ISO 8859-2 Central European"), "latin5" => $clang->gT("ISO 8859-9 Turkish"), "latin7" => $clang->gT("ISO 8859-13 Baltic"), "macce" => $clang->gT("Mac Central European"), "macroman" => $clang->gT("Mac West European"), "sjis" => $clang->gT("Shift-JIS Japanese"), "swe7" => $clang->gT("7bit Swedish"), "tis620" => $clang->gT("TIS620 Thai"), "ucs2" => $clang->gT("UCS-2 Unicode"), "ujis" => $clang->gT("EUC-JP Japanese"), "utf8" => $clang->gT("UTF-8 Unicode"));
     if (Yii::app()->request->getPost('submit')) {
         if (Yii::app()->request->getPost('csvcharset') && Yii::app()->request->getPost('csvcharset')) {
             $uploadcharset = Yii::app()->request->getPost('csvcharset');
             if (!array_key_exists($uploadcharset, $aEncodings)) {
                 $uploadcharset = 'auto';
             }
             $filterduplicatetoken = Yii::app()->request->getPost('filterduplicatetoken') && Yii::app()->request->getPost('filterduplicatetoken') == 'on';
             $filterblankemail = Yii::app()->request->getPost('filterblankemail') && Yii::app()->request->getPost('filterblankemail') == 'on';
         }
         $attrfieldnames = getAttributeFieldNames($iSurveyId);
         $duplicatelist = array();
         $invalidemaillist = array();
         $invalidformatlist = array();
         $firstline = array();
         $sPath = Yii::app()->getConfig('tempdir');
         $sFileName = $_FILES['the_file']['name'];
         $sFileTmpName = $_FILES['the_file']['tmp_name'];
         $sFilePath = $sPath . '/' . $sFileName;
         if (!@move_uploaded_file($sFileTmpName, $sFilePath)) {
             $aData['sError'] = $clang->gT("Upload file not found. Check your permissions and path ({$sFilePath}) for the upload directory");
             $aData['aEncodings'] = $aEncodings;
             $aData['iSurveyId'] = $aData['surveyid'] = $iSurveyId;
             $aData['thissurvey'] = getSurveyInfo($iSurveyId);
             $this->_renderWrappedTemplate('token', array('tokenbar', 'csvupload'), $aData);
         } else {
             $xz = 0;
             $recordcount = 0;
             $xv = 0;
             // This allows to read file with MAC line endings too
             @ini_set('auto_detect_line_endings', true);
             // open it and trim the ednings
             $tokenlistarray = file($sFilePath);
             $sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language;
             if (!Yii::app()->request->getPost('filterduplicatefields') || Yii::app()->request->getPost('filterduplicatefields') && count(Yii::app()->request->getPost('filterduplicatefields')) == 0) {
                 $filterduplicatefields = array('firstname', 'lastname', 'email');
             } else {
                 $filterduplicatefields = Yii::app()->request->getPost('filterduplicatefields');
             }
             $separator = returnGlobal('separator');
             foreach ($tokenlistarray as $buffer) {
                 $buffer = @mb_convert_encoding($buffer, "UTF-8", $uploadcharset);
                 $firstname = "";
                 $lastname = "";
                 $email = "";
                 $emailstatus = "OK";
                 $token = "";
                 $language = "";
                 $attribute1 = "";
                 $attribute2 = "";
                 //Clear out values from the last path, in case the next line is missing a value
                 if ($recordcount == 0) {
                     // Pick apart the first line
                     $buffer = removeBOM($buffer);
                     $allowedfieldnames = array('firstname', 'lastname', 'email', 'emailstatus', 'token', 'language', 'validfrom', 'validuntil', 'usesleft');
                     $allowedfieldnames = array_merge($attrfieldnames, $allowedfieldnames);
                     switch ($separator) {
                         case 'comma':
                             $separator = ',';
                             break;
                         case 'semicolon':
                             $separator = ';';
                             break;
                         default:
                             $comma = substr_count($buffer, ',');
                             $semicolon = substr_count($buffer, ';');
                             if ($semicolon > $comma) {
                                 $separator = ';';
                             } else {
                                 $separator = ',';
                             }
                     }
                     $firstline = convertCSVRowToArray($buffer, $separator, '"');
                     $firstline = array_map('trim', $firstline);
                     $ignoredcolumns = array();
                     //now check the first line for invalid fields
                     foreach ($firstline as $index => $fieldname) {
                         $firstline[$index] = preg_replace("/(.*) <[^,]*>\$/", "\$1", $fieldname);
                         $fieldname = $firstline[$index];
                         if (!in_array($fieldname, $allowedfieldnames)) {
                             $ignoredcolumns[] = $fieldname;
                         }
                     }
                     if (!in_array('firstname', $firstline) || !in_array('lastname', $firstline) || !in_array('email', $firstline)) {
//.........这里部分代码省略.........
开发者ID:rawaludin,项目名称:LimeSurvey,代码行数:101,代码来源:tokens.php

示例11: CSVImportQuestion


//.........这里部分代码省略.........
    }
    for ($i = 0; $i <= $stoppoint + 1; $i++) {
        if ($i < $stoppoint - 2) {
            $labelsetsarray[] = $bigarray[$i];
        }
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    //LABELS
    if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray)) {
        $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
    } elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray)) {
        $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
    } else {
        $stoppoint = count($bigarray) - 1;
    }
    for ($i = 0; $i <= $stoppoint + 1; $i++) {
        if ($i < $stoppoint - 2) {
            $labelsarray[] = $bigarray[$i];
        }
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    //Question_attributes
    $stoppoint = count($bigarray);
    for ($i = 0; $i <= $stoppoint + 1; $i++) {
        if ($i < $stoppoint - 1) {
            $question_attributesarray[] = $bigarray[$i];
        }
        unset($bigarray[$i]);
    }
    $bigarray = array_values($bigarray);
    if (isset($questionarray)) {
        $questionfieldnames = convertCSVRowToArray($questionarray[0], ',', '"');
        unset($questionarray[0]);
        $countquestions = count($questionarray) - 1;
    } else {
        $countquestions = 0;
    }
    if (isset($answerarray)) {
        $answerfieldnames = convertCSVRowToArray($answerarray[0], ',', '"');
        unset($answerarray[0]);
        $countanswers = count($answerarray);
    } else {
        $countanswers = 0;
    }
    if (isset($labelsetsarray)) {
        $countlabelsets = count($labelsetsarray) - 1;
    } else {
        $countlabelsets = 0;
    }
    if (isset($labelsarray)) {
        $countlabels = count($labelsarray) - 1;
    } else {
        $countlabels = 0;
    }
    if (isset($question_attributesarray)) {
        $countquestion_attributes = count($question_attributesarray) - 1;
    } else {
        $countquestion_attributes = 0;
    }
    $aLanguagesSupported = array();
    // this array will keep all the languages supported for the survey
    $sBaseLanguage = GetBaseLanguageFromSurveyID($newsid);
    $aLanguagesSupported[] = $sBaseLanguage;
    // adds the base language to the list of supported languages
开发者ID:ddrmoscow,项目名称:queXS,代码行数:67,代码来源:importquestion.php


注:本文中的convertCSVRowToArray函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。