Differences From Artifact [1629f5904f]:

To Artifact [88c627e4f9]:


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
		$membres = new Membres;

		// On récupère les champs qu'on peut importer
		$champs = Config::getInstance()->get('champs_membres')->getAll();
		$champs = array_keys((array)$champs);
		$champs[] = 'date_inscription';
		//$champs[] = 'date_connexion';
		$champs[] = 'id';
		//$champs[] = 'id_categorie';

		$line = 0;
		$delim = Utils::find_csv_delim($fp);

		while (!feof($fp))
		{







|







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
		$membres = new Membres;

		// On récupère les champs qu'on peut importer
		$champs = Config::getInstance()->get('champs_membres')->getAll();
		$champs = array_keys((array)$champs);
		$champs[] = 'date_inscription';
		//$champs[] = 'date_connexion';
		//$champs[] = 'id';
		//$champs[] = 'id_categorie';

		$line = 0;
		$delim = Utils::find_csv_delim($fp);

		while (!feof($fp))
		{
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236

237

238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256



257
258
259
260
261
262
263
264
				if (!in_array($name, $champs))
					continue;

				if (trim($row[$id]) !== '')
					$data[$name] = $row[$id];
			}

			if (!empty($data['id']) && $data['id'] > 0)
			{
				$id = (int)$data['id'];
			}
			else
			{
				$id = false;
			}

			unset($data['id']);

			try {
				if ($id)

					$membres->edit($id, $data);

				else

					$membres->add($data);

			}
			catch (UserException $e)
			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : ' . $e->getMessage());
			}
		}

		$db->commit();

		fclose($fp);
		return true;
	}

    public function toCSV()
    {
        $db = DB::getInstance();




        $res = $db->prepare('SELECT m.id, c.nom AS categorie, m.* FROM membres AS m 
            LEFT JOIN membres_categories AS c ON m.id_categorie = c.id ORDER BY c.id;')->execute();

        $fp = fopen('php://output', 'w');
        $header = false;

        while ($row = $res->fetchArray(SQLITE3_ASSOC))
        {







|

|



|


|


|
>

>

>

>


















>
>
>
|







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
				if (!in_array($name, $champs))
					continue;

				if (trim($row[$id]) !== '')
					$data[$name] = $row[$id];
			}

			if (!empty($data['numero']) && $data['numero'] > 0)
			{
				$numero = (int)$data['numero'];
			}
			else
			{
				$numero = false;
			}

			unset($data['numero']);

			try {
				if ($numero && ($id = $membres->getIDWithNumero($numero)))
				{
					$membres->edit($id, $data);
				}
				else
				{
					$membres->add($data);
				}
			}
			catch (UserException $e)
			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : ' . $e->getMessage());
			}
		}

		$db->commit();

		fclose($fp);
		return true;
	}

    public function toCSV()
    {
        $db = DB::getInstance();

        $champs = Config::getInstance()->get('champs_membres')->getKeys();
        $champs = 'm.' . implode(', m.', $champs);

        $res = $db->prepare('SELECT ' . $champs . ', c.nom AS categorie FROM membres AS m 
            LEFT JOIN membres_categories AS c ON m.id_categorie = c.id ORDER BY c.id;')->execute();

        $fp = fopen('php://output', 'w');
        $header = false;

        while ($row = $res->fetchArray(SQLITE3_ASSOC))
        {